VB.NET Send e-mail


Imports System.Net.Mail

Sub SendMail()
   Try
      Dim SmtpServer As New SmtpClient()
      Dim mail As New MailMessage()

      'SMTP Server – Login & Password
      SmtpServer.Credentials = New Net.NetworkCredential("mail@abc.com", "123456")

      'SMTP Server – Port No.
      SmtpServer.Port = 25

      'SMTP Server Host
      SmtpServer.Host = "smtp.abc.com"

      'Mail Address From
      mail.From = New MailAddress("mail@abc.com")

      'Mail Address To
      mail.To.Add("pkson@abc.com")

      'Mail Subject
      mail.Subject = " Mail Subject "

      'Mail Content
      mail.Body = " Mail Content "

      'Mail Sent
      SmtpServer.Send(mail)

      'Alert Message
      MsgBox("Mail Sent")
   Catch ex As Exception
      'Error Message if error occur
      MsgBox(ex.ToString)
   End Try
End Sub

發表留言