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.
- Add the following code in the code editor.
- Imports System.Net.Mail
- Public Class Form1
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim E_Mail As New MailMessage
- E_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 = True
- smtp.Credentials = New System.Net.NetworkCredential("username", "password")
- smtp.Port = "587"
- End Sub
- End Class
Readers might read also: