How To Send Email In Visual Basic VB.NET - Codebun
Có thể bạn quan tâm
SMTP Authentication
It provides a set of protocols that simplify the communication of email messages between email servers. Most SMTP server names are written in the form “smtp.domain.com” or “mail.domain.com”: for example, a Gmail account will refer to smtp.gmail.com. Most email systems that send mail over the Internet use SMTP to send messages from one server to another, the messages can be retrieved with an email client using either POP or IMAP.
Smtp_Server.Credentials = New _ Net.NetworkCredential("[email protected]", "password")You must provide your email address in the place of “[email protected]” and the real password of your given Gmail account in the place of “password” for credentials.
Sending Email through Gmail in VB.NetHow do I send mail using VB.Net?
VB.NET uses SMTP protocol for sending emails. SMTP stands for Simple Mail Transfer Protocol. VB.NET using System.Net.Mail namespace for sending mail. We can instantiate SmtpClient class and assign the Host and Port.
Using Gmail Server:
The Gmail SMTP server name is smtp.gmail.com and the port using send mail is 587. Here using Network Credential for password-based authentication.
Here we have to provide the information like our Gmail username and password, and then to address also.
The below example demonstrates how to send mail using the SmtpClient class. The following points to be noted in this are −
- We must specify the SMTP host server that you use to send e-mails. The Host and Port properties will be different for the different host servers. We will be using a Gmail server.
- We need to give the Credentials for authentication if required by the SMTP server.
- We should also provide the email address of the sender and the e-mail address or addresses of the recipients using the MailMessage.From and MailMessage.To properties, respectively.
- We should also specify the message content using the MailMessage.Body property.
Example:
In this example, we will create a simple application that would send an e-mail, here we will send an email to ourselves for testing the application. Use the following steps −
Step 1:
Open your Visual Studio > Go to File Menu > Click on New Project > Select Visual Basic Windows Application > Name the Project and then > Click on OK.

Step 2:
On Form1 Take three labels, three text boxes, and one-button control from the toolbox. Change the text properties of the labels to – ‘From:‘, ‘To:‘ and ‘Message:‘ respectively. Change the text property of the button control to ‘Send‘.

Step 3:
First of all add the following namespaces on top of the code window.
Imports System.Net.Mail Imports System.NetBelow the public class Form1 add the following code,
Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.Text = "Email Sending App" End SubDouble click on the Send button and add the following code there.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Try Dim Smtp_Server As New SmtpClient Dim e_mail As New MailMessage() Smtp_Server.UseDefaultCredentials = False Smtp_Server.Credentials = New Net.NetworkCredential("[email protected]", "password") Smtp_Server.Port = 587 Smtp_Server.EnableSsl = True Smtp_Server.Host = "smtp.gmail.com" Smtp_Server.DeliveryMethod = SmtpDeliveryMethod.Network e_mail = New MailMessage() e_mail.From = New MailAddress(Textbox1.Text) e_mail.To.Add(TextBox2.Text) e_mail.Subject = "Email Sending" e_mail.IsBodyHtml = False e_mail.Body = TextBox3.Text Smtp_Server.Send(e_mail) MsgBox("Mail Sent") Catch ex As Exception MsgBox(ex.ToString) End Try End SubYou must provide your email address and real password for credentials.

Step 4:
Run the Application.
Output:
When we press F5 and run the application. First, we will see the Form1 just shown below image Fill your email address in From field and other person’s email address in the field of To whom you want to send mail. Write the message in message field and click on Send. The message will sent to that person and it will show the message box with the text “Mail Sent”. As shown in the below image.

Here in this example we have trying to send emails to ourselves that is why we fill our email address in both fields of TextBoxes in From: and To:

Từ khóa » Visual Basic Send Email
-
Sending Email From Visual Basic - Stack Overflow
-
VB.Net - Send Email - Tutorialspoint
-
How To Send Emails Using VB.NET - YouTube
-
How To: Programmatically Send Email - Visual Studio (Windows)
-
Sending Email Using VBnet And Smtp. - Microsoft Q&A
-
Send Email In VB.NET - Tutorial - AdminSystem Software Limited
-
Send Email In VB 6.0 - Example Codes
-
VBA Send Email From Excel - WallStreetMojo
-
How To Send Email Using VB.Net - The Crazy Programmer
-
Send Email From C# / VB.NET / ASP.NET Using SMTP - GemBox
-
Sending EMails With Visual Basic With LinkedResources ... - CodeGuru
-
Visual Basic Script To Send Email - Oracle Help Center
-
What Is SMTP - Net
-
Send An Email With Outlook Using VB .Net - Visual Basic .NET - Bytes