+92 332 4229 857 99ProjectIdeas@Gmail.com

How to Send Emails Through SMTP (Vb.net)



Send Emails Through SMTP-Simple Mail Transfer Protocol
Libraries used for sending mails through SMTP are:
Imports System.Net
Imports System.Net.Mail

Imports System.Net used for NetworkCredential
Imports System.Net.Mail used for MailMessage

SmtpClient("smtp.gmail.com") allows applicationsto send emails through SMTP.
587 is the port number for sending emails through SMTP.

Code

Sub sendMail()
Try
Dim AnEmailMessage As New MailMessage
AnEmailMessage.From = New MailAddress(txt_GmaiLUsername.Text)
AnEmailMessage.To.Add(TXT_TO.Text)
AnEmailMessage.Subject = (TXT_Subject.Text)
AnEmailMessage.Body = (TXT_Body.Text)
AnEmailMessage.Priority = MailPriority.High
Dim SimpleSMTP As New SmtpClient("smtp.gmail.com")
With SimpleSMTP
.Port = 587
.EnableSsl = True
.Credentials = _
New NetworkCredential(txt_GmaiLUsername.Text, txt_GmailPassword.Text)
.Send(AnEmailMessage)
End With
MsgBox("Email sent to : " & TXT_TO.Text, MsgBoxStyle.Information)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub

1 comments:

Anonymous said...

Your information about VB scripts is really interesting and innovative. Also I want you to share latest updates about this VB. Can you update it in your website? Thanks for sharing

Dot net training institute in Chennai