Send an Email With VB.net

Very Easy and I think all we know it, but want to add it...
'Need to declare this
' Add it also !!!
Imports System.Web.mail

Then this do all the work you need ...

'send the email
Try
Dim insMail As New MailMessage()
With insMail
.From = "omar.abid2006@gmail.com"
.To = "omar.abid2006@gmail.com"
.Subject = "test"
.Body = "test sending email"
End With
SmtpMail.SmtpServer = "your smtp server"
SmtpMail.Send(insMail)
Console.WriteLine("Successfully sent email message" + vbCrLf)
Catch err As Exception
Console.WriteLine("EXCEPTION " + err.Message + vbCrLf)
End Try

0 comments:

Post a Comment