Send Email using Vb.NET

Posted by Venkat | Labels: , ,

Now we have to discuss how to send email using GMAIL server.

Normally we can use , Gmail, Yahoo , etc.. some company having own mailserver so you have to contact your Admin to know your mailserver , id , pwd etc..

This is code to send email using Vb.Net

Imports System.Net.Mail

Protected  Sub Button1_Click
(ByVal sender As Object, ByVal e As EventArgs)
Dim mail As MailMessage =  New MailMessage()
mail.To.Add("admin@gmail.com")
mail.From = New MailAddress("admin@gmail.com")
mail.Subject = "Email using Gmail server "

dim Body as String = "Hi, this mail is to test sending mail"+
             "using Gmail in ASP.NET using vb.Net"
mail.Body = Body

mail.IsBodyHtml = True
Dim smtp As SmtpClient =  New SmtpClient()
smtp.Host = "smtp.gmail.com" 
smtp.EnableSsl = True 
smtp.Credentials = New System.Net.NetworkCredential
    ("YourUserName@gmail.com","YourGmailPassword")
smtp.Send(mail)
End Sub

0 comments:

Post a Comment

Thanks for the Comments.

PayOffers.in