Created
April 25, 2014 01:33
-
-
Save sir4ju1/11275242 to your computer and use it in GitHub Desktop.
Send EMail using Gmail from ASP Web application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void SendMail() | |
{ | |
MailMessage msg = new MailMessage(); | |
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(); | |
try | |
{ | |
msg.Subject = "Add Subject"; | |
msg.Body = "Add Email Body Part"; | |
msg.From = new MailAddress("Valid Email Address"); | |
msg.To.Add("Valid Email Address"); | |
msg.IsBodyHtml = true; | |
client.Host = "smtp.gmail.com"; | |
System.Net.NetworkCredential basicauthenticationinfo = new System.Net.NetworkCredential("Valid Email Address", "Password"); | |
client.Port = int.Parse("587"); | |
client.EnableSsl = true; | |
client.UseDefaultCredentials = false; | |
client.Credentials = basicauthenticationinfo; | |
client.DeliveryMethod = SmtpDeliveryMethod.Network; | |
client.Send(msg); | |
} | |
catch (Exception ex) | |
{ | |
log.Error(ex.Message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment