I’ve been trying to setup a web form to send mail using my google account, but I have repeatedly had no luck. I’ve found many posts about people who are having the same problems, but have yet to come across a viable solution. Here is the code, if you see something that is incorrect, please let me (and others) know how to fix it.

System.Net.Mail.MailMessage mail = new MailMessage();
mail.From = new MailAddress("no-reply@mydomain.com", "Do Not Reply");
mail.To.Add(new MailAddress("email@mydomain.com", "My Email"));
mail.Subject = "Email Subject";
mail.Body = message;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.EnableSsl = true;
client.Port = 587;
client.Host = "smtp.google.com";
client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new System.Net.NetworkCredential("no-reply@mydomain.com", "password");
client.Send(mail);

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>