Ad Code

Responsive Advertisement

How To Send Email using vb.net

Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New _
Net.NetworkCredential("your gmail id", "your email password")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage()
mail.From = New MailAddress("your gmail id same as above")
mail.To.Add("recipient email id")
mail.Subject = subject
mail.Body = "Dear User, " & Environment.NewLine & Environment.NewLine & eb & Environment.NewLine & Environment.NewLine & "Regards," & Environment.NewLine & "HowToCodeIt"
SmtpServer.Send(mail)
MsgBox("Notification emailed successfully")
Catch ex As Exception
MsgBox(ex.ToString)
End Try

Note that SMTP details are for GMAIL. If you want to send email from some other provider say Yahoo or Rediff then google internet for their SMTP Port and Host details and do approp. replacement in the above code...

Also, as you can see that body is read from windows controls..same can be done for subject and email address of recipient etc.

Post a Comment

1 Comments

  1. Add following import for code to work:
    Imports System.Net.Mail

    ReplyDelete