ASP.Net SMTP Example

From Hostek.com Wiki
Revision as of 08:47, 30 December 2012 by Chadc (Talk | contribs)

Jump to: navigation, search

Examples for sending mail with ASP.Net

C#

System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient("smtpmailer.hostek.net", 25);
smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtpClient.Timeout = 60000;
smtpClient.EnableSsl = false;

System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
mailMessage.From = new System.Net.Mail.MailAddress("from_address@hostek_example.com", "from_display_name");
mailMessage.To.Add("to_address@hostek_example.com");
mailMessage.Bcc.Add("bcc_address@hostek_example.com");

mailMessage.Subject = "Email Subject";
mailMessage.IsBodyHtml = false;
mailMessage.Body = "Email Body";
smtpClient.Send(mailMessage);

VB

Dim smtpClient As New System.Net.Mail.SmtpClient("smtpmailer.hostek.net", 25)
smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
smtpClient.Timeout = 60000
smtpClient.EnableSsl = False

Dim mailMessage As New System.Net.Mail.MailMessage()
mailMessage.From = New System.Net.Mail.MailAddress("from_address@hostek_example.com", "from_display_name")
mailMessage.To.Add("to_address@hostek_example.com")
mailMessage.Bcc.Add("bcc_address@hostek_example.com")

mailMessage.Subject = "Email Subject"
mailMessage.IsBodyHtml = False
mailMessage.Body = "Email Body"
smtpClient.Send(mailMessage)