Sending email using ASP.NET (VB.NET)

To send email via ASP.NET (VB.NET), please refer to following sample code.

Note: Our mail servers require your script to pass SMTP authentication in order to send email through script.

Sample Code:

Imports System.Net.Mail
Imports System.Net

//The following code should be inside your send mail routine.
Try
   Dim mmMessage As New MailMessage()

   Dim ncSMTPDetails As New System.Net.NetworkCredential()
   Dim SMTP As New SmtpClient()

   Dim strSenderEmail As String = "SENDER_EMAIL_ADDRESS"
   Dim strSender As String = "SENDER_NAME"
   Dim strSenderPassword = "SENDER_PASSWORD"

   Dim strRecipientEmail As String = "RECIPIENT_EMAIL_ADDRESS"
   Dim strRecipient As String = "RECIPIENT_NAME"

   Dim strSMTPHost As String = "mail.yourdomain.com"
   Dim strSMTPPort As String = "2525"

   '-- Build Message
   mmMessage.From = New MailAddress(strSenderEmail, strSender)
   mmMessage.To.Add(New MailAddress(strRecipientEmail, strRecipient))

   mmMessage.IsBodyHtml = False
   mmMessage.Priority = MailPriority.Normal

   mmMessage.Subject = "YOUR_EMAIL_SUBJECT"
   mmMessage.Body = "YOUR_MESSAGE"

   '-- Define Authenticated User
   ncSMTPDetails.UserName = strSenderEmail
   ncSMTPDetails.Password = strSenderPassword

   '-- Send Message
   SMTP.UseDefaultCredentials = False
   SMTP.Credentials = ncSMTPDetails
   SMTP.Host = strSMTPHost
   SMTP.Port = strSMTPPort

   SMTP.DeliveryMethod = SmtpDeliveryMethod.Network

   SMTP.Send(mmMessage)

Catch Err As Exception
End Try

//Remember to replace "yourdomain.com" with your actual domain name.

  • 2 Usuários acharam útil
Esta resposta lhe foi útil?

Artigos Relacionados

Sending email using ASP.NET (C#)

To send email via ASP.NET (C#), please refer to following sample code. Note: Our mail servers...