Promote Your Blog

Friday, March 2, 2012

How To Send Email using

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 = ""
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"
MsgBox("Notification emailed successfully")
Catch ex As Exception
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.

1 comment:

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