Created
July 2, 2013 13:05
-
-
Save davidalencar/5909139 to your computer and use it in GitHub Desktop.
Sending e-mail via .NET framework. Server with authentication SSL
This file contains 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
private void sendEmail() | |
{ | |
SmtpClient client = new SmtpClient(); | |
client.DeliveryMethod = SmtpDeliveryMethod.Network; | |
client.Host = "smtp.domain.com"; | |
client.Port = 587; | |
// setup Smtp authentication | |
System.Net.NetworkCredential credentials = | |
new System.Net.NetworkCredential("user@domain.com", "password"); | |
client.UseDefaultCredentials = false; | |
client.Credentials = credentials; | |
MailMessage msg = new MailMessage(); | |
msg.From = new MailAddress("email_From@tdomain.com"); | |
msg.To.Add(new MailAddress("email_To@domain.com")); | |
msg.Subject = "This is a test Email subject"; | |
msg.IsBodyHtml = true; | |
msg.Body = string.Format("<html><head></head><body><b>Test HTML Email</b></body>"); | |
try | |
{ | |
client.Send(msg); | |
MessageBox.Show("Your message has been successfully sent."); | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show("Error occured while sending your message." + ex.Message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment