This Visual Basic Tutorial is all about Sending an Email.
In Visual Basic, sending e-mails are allowed in your application. The System.Net.Mail is the namespace that contains classes that is used for sending e-mails to a Simple Mail Transfer Protocol (SMTP) server for delivery.
The SmtpClient class allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP).
Take note that in sending e-mail you must specify the SMTP host server because the Host and Port properties will be different for various host server.
In here, we will be using Gmail server.
If the STMP server requires you for the authentication, you must need to give the Credentials
Sender’s email address should be provided same as the recipients using the MailMessage.From and MailMessage.To properties. Specify also the content of message by using MailMessage.Body property.
- Open the Visual Basic, select “File” on the menu, hit new and create a new project.
- The New Project dialog will appear.
Select “windows” in the project types, hit the “windows form application” in the templates and hit “ok“.
- Design the form this way. See it Below.
- dd the following code in the code editor.Visual Basic1234567891011121314Imports System.Net.MailPublic Class Form1Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim E_Mail As New MailMessageE_Mail.Subject = "Emailling"E_Mail.To.Add("[email protected]")E_Mail.From = New MailAddress("[email protected]")E_Mail.Body = "This is an email from VB.NET"Dim smtp As New SmtpClient("smtp.gmail.com")smtp.EnableSsl = Truesmtp.Credentials = New System.Net.NetworkCredential("username", "password")smtp.Port = "587"smtp.Send(E_Mail)End SubEnd Class
Readers might read also: