Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Button3_Click(object sender, EventArgs e)
{
   DateTime s = new DateTime();
   s = DateTime.Now;  
   MailMessage msg = new MailMessage();
   msg.From = new MailAddress("xxxx@gmail.com");
   msg.To.Add("zzzzzzz@gmail.com");
   msg.Subject = "for enquiry";
   msg.Body = "Company/Organization Name :" + TextBox4.Text + "\n Name :" + TextBox5.Text + "\n Email ID :" + TextBox6.Text + "\n Mobile No :" + TextBox7.Text + "\n Phone No :" + TextBox8.Text + "\n Fax No :" + TextBox9.Text + "\n Requirement/Enquiry :" + TextBox10.Text+"\n Address:" + TextBox11.Text+"\n City :" + TextBox3.Text+"\n Zip Code :" + TextBox2.Text+"\n Country :" + TextBox1.Text+"\n Date:" + s;
   SmtpClient smtpclient = new SmtpClient();
   smtpclient.Host = "smtp.gmail.com";
   smtpclient.Port = 587;
   smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network;
   smtpclient.UseDefaultCredentials = false;
   smtpclient.Credentials = new System.Net.NetworkCredential("xxxxx@gmail.com", "password");
    smtpclient.EnableSsl = true;
   smtpclient.Send(msg);
}
Posted
v2
Comments
Use Try Catch Block to handle the Exception and tell us what is the Exception.
Joezer BH 3-Sep-13 2:25am    
5ed! :)
Thanks... :)
P_Dash 3-Sep-13 2:18am    
Try with using Port number 25 or 465.
I guess you are having some port issues.
Because all configurations & everything is fine with your Code.
MTProgrammer 3-Sep-13 16:52pm    
https://support.google.com/mail/answer/78775?hl=en
Specifically the second question.

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