ASP.Net SMTP Example

From Hostek.com Wiki
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("[email protected]_example.com", "from_display_name");
 mailMessage.To.Add("[email protected]_example.com");
 mailMessage.Bcc.Add("[email protected]_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("[email protected]_example.com", "from_display_name")
 mailMessage.To.Add("[email protected]_example.com")
 mailMessage.Bcc.Add("[email protected]_example.com")
 
 mailMessage.Subject = "Email Subject"
 mailMessage.IsBodyHtml = False
 mailMessage.Body = "Email Body"
 smtpClient.Send(mailMessage)
%>