Click here to Skip to main content
16,019,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a contact page for my website and in that contact page i have Name field , Email field , Subject Field , and Message Field and on submission of form ... i sent all the details on my email id .

My question is that to send all the information to my email id do i need to mention my mail id in to and from address both ... i am confused with to and from email address

if u have any suggestions please help.

code is :

protected void btnSend_Click(object sender, EventArgs e)
{
MailMessage mm = new MailMessage("sender@gmail.com", "receiver@gmail.com");
mm.Subject = txtSubject.Text;
mm.Body = "Name: " + txtName.Text + "

Email: " + txtEmail.Text + "
" + txtBody.Text;

mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "sender@gmail.com";
NetworkCred.Password = "xxxxx";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
lblMessage.Text = "Email Sent SucessFully.";
}
Posted

1 solution

To field is for the recipient, the one who receives it whereas From field is for sender, the one sends the email. SMTP servers or clients would use these parameters to generate a GUI for the client to read who sent the email or who was sent the email.

In cases where you are going to send an email to yourself, you can fill in both with your own email address. SMTP servers won't complain about both being the same. If you want to send an email to additional (or some other) email address, add that to "To" field and leave yours as the one you own.

It totally depends on your need.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900