How To Send Email Using VB.Net - The Crazy Programmer
Có thể bạn quan tâm
In visual basic.net we use SMTP i.e Simple Mail Transfer Protocol which helps us in composing electronic mails and sending them to various sources.
Also Read: SQL Injection Attacks – How to Prevent VB.Net Database Applications
We need to import the following namespace “Imports System.Net.Mail” in order to use the SMTP class.
About System.Net.Mail Namespace
This Namespace provides various list of classes that help us to create, send, receive and do many other email related tasks.
You can get more detailed information from the Microsoft Developer Network’s website http://msdn.microsoft.com/en-us/library/system.net.mail(v=vs.110).aspx
How to Send Email Using VB.Net
I’ll demonstrate a simple example that allows us to send emails in vb.net:
1. Create a new windows form application project in visual basic.net.
2. Add three labels and three textboxes and name them as given below:
Label1 – To Label2 – Subject Label3 – Body
3. Add a button and change its text to Send.
4. Double click button to switch to code view and paste the code given below.
Dim MyMailMessage As New MailMessage() Try MyMailMessage.From = New MailAddress("youremail") MyMailMessage.To.Add(TextBox1.Text) MyMailMessage.Subject = TextBox2.Text MyMailMessage.Body = TextBox3.Text Dim SMTP As New SmtpClient("smtp.gmail.com") SMTP.Port = 587 SMTP.EnableSsl = True SMTP.Credentials = New System.Net.NetworkCredential("youremail", "yourpassword") SMTP.Send(MyMailMessage) MsgBox("Your Mail has been Successfully sent") TextBox1.Clear() TextBox2.Clear() TextBox3.Clear() TextBox1.Focus() Catch ex As Exception MsgBox(ex.ToString) End Try5. Change youremail with your current email address and yourpassword with your email ID’s password. Don’t forget to import the following namespace: Imports System.Net.Mail
That’s it!! Run your Project and send a test email.
Note: It works only with Gmail Account because we have used Gmail’s SMTP Port.
Từ khóa » Visual Basic Send Email
-
Sending Email From Visual Basic - Stack Overflow
-
VB.Net - Send Email - Tutorialspoint
-
How To Send Email In Visual Basic VB.NET - Codebun
-
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
-
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