Difference between revisions of "ASP.Net SMTP Example"

From Hostek.com Wiki
Jump to: navigation, search
(Created page with "Exampels for sending mail with ASP.Net ==C#== System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient("smtpmailer.hostek.net", 25); smtpClient.DeliveryMetho...")
 
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
Exampels for sending mail with ASP.Net
+
Examples for sending mail with ASP.Net
  
 
==C#==
 
==C#==
 
+
<syntaxhighlight lang="csharp">
 +
<%
 
  System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient("smtpmailer.hostek.net", 25);
 
  System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient("smtpmailer.hostek.net", 25);
 
  smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
 
  smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
Line 17: Line 18:
 
  mailMessage.Body = "Email Body";
 
  mailMessage.Body = "Email Body";
 
  smtpClient.Send(mailMessage);
 
  smtpClient.Send(mailMessage);
 
+
%>
 +
</syntaxhighlight>
 
==VB==
 
==VB==
  
 +
<syntaxhighlight lang="vbnet">
 +
<%
 
  Dim smtpClient As New System.Net.Mail.SmtpClient("smtpmailer.hostek.net", 25)
 
  Dim smtpClient As New System.Net.Mail.SmtpClient("smtpmailer.hostek.net", 25)
 
  smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
 
  smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
Line 34: Line 38:
 
  mailMessage.Body = "Email Body"
 
  mailMessage.Body = "Email Body"
 
  smtpClient.Send(mailMessage)
 
  smtpClient.Send(mailMessage)
 
+
%>
 +
</syntaxhighlight>
 
[[Category:ASP.Net Tutorials]]
 
[[Category:ASP.Net Tutorials]]

Latest revision as of 17:43, 23 May 2013

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)
%>