In this article you are going to learn How to send an email message Using VB.Net. To send an email from the Visual Basics, we have to use the SMTP protocol. SMTP means "Simple Mail Transfer Protocol".Some times it is difficult to get the result even every thing is fine in the code then the problem is with SMTP authentication.Following is an name space needs to be imported to the code.
[vbnet]Imports System.Web.Mail[/vbnet]
Step-1
Follow the below steps to send an email from the VB.Net.
Open Visual Studio 2013.
Go to File->New->Project as shown in the below figure.
Step-2
Select the Console Application and also give the Name as shown in the below figure.
Step-3
Go to Project and click on the Add Reference as shown in the below figure.
Step-4
Select the Framework and then select the System.Web as shown in the below figure.
Step-5
Click on OK. Then you will get the reference for the System.Web.Mail.Write the following code in the Module1.vb.Run the Application and check the emails to see the result.
[vbnet]
Imports System.Web.Mail
Module Module1
Sub Main()
Dim Msg As MailMessage = New MailMessage()
'sender e-mail address
Msg.From = "devid@gmail.com"
'recipient e-mail address.
Msg.To = "John@gmail.com"a
Msg.Subject = "Splessons"
Msg.BodyFormat = MailFormat.Html
Msg.Body = "Welcome to SPlessons"
'Attachment
Dim File As String = "C:\Users\hp pavillion\Documents\Data Type.docx"
Dim Attach As MailAttachment = New MailAttachment(File, MailEncoding.Base64)
Msg.Attachments.Add(Attach)
'remote SMTP server.
SmtpMail.SmtpServer = "Smtp.gmail.com"
SmtpMail.Send(Msg)
Msg = Nothing
Attach = Nothing
End Sub
End Module
[/vbnet]
Summary
Points
SMTP is a email transmission.
System.Web.Mail will consists of all the classes to send an mail.
For mail submission SMTP uses the port number 587.