Aug 25, 2016 02:44 PM
(This post was last modified: Aug 25, 2016 02:46 PM by Mr Reddington.)
Hello everybody,
Thought i would release a quick little tutorial for beginners to learn how to make a simple SMTP Mailer in Visual Basics. It could also be used as a Mass Mailer (aka: Bulk mailer) . It is a very simple tutorial and as I said it is for beginners so nothing advanced.
Hope you all enjoy the tutorial is below.
1. Step one, start a new project in Visual Studio make it a Visual Basic - windows application project . Name it what ever you like
2. In form1.vb create 7 new text boxes.
3. In form1.vb create 7 new labels
4. Have the layout like so:
https://imgur.com/a/nNhUT
5. Double click any where on the form to bring up the coding area.
6. Place the following code at the start:
Explained: This imports the tools needed to run mailer along with setting the label names.
7. Create two buttons one called "Send" and another called "closed", you can put them side by side at the bottom of the form
8. Double click on the send button, then input the code between the "private Sub Button1_Click"
9. Next double click on the "close" button, the input the following code between "Private Sub Button2_Click"
10. You are now done, you have created your first SMTP Mailer
EXTRA NOTES:
- For text box 6 and 7 make them multiple input so you can put in multiple email address and also be able to type a email.
- You don't have to keep this layout you can change it how ever you want.
- You can also change the label names in there property's, you don't have to have it coded like at the start.
- As I stated at the start this is a very basic SMTP Mailer and is just for beginners to learn.
- This can be used as a mass mailer (bulk mailer) if user wanted to.
If you have any questions at all feel free to ask, this is for educational purposes.
Hope you all like it.
Thought i would release a quick little tutorial for beginners to learn how to make a simple SMTP Mailer in Visual Basics. It could also be used as a Mass Mailer (aka: Bulk mailer) . It is a very simple tutorial and as I said it is for beginners so nothing advanced.
Hope you all enjoy the tutorial is below.
1. Step one, start a new project in Visual Studio make it a Visual Basic - windows application project . Name it what ever you like
2. In form1.vb create 7 new text boxes.
3. In form1.vb create 7 new labels
4. Have the layout like so:
https://imgur.com/a/nNhUT
5. Double click any where on the form to bring up the coding area.
6. Place the following code at the start:
Code
Imports System.Net.Mail
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Label1.Text = ("SMTP Server")
Label2.Text=('Port")
Label3.Text = ("Email Address (Sending From)")
Label4.Text = ("Password")
Label5.Text = ("Email Addresses (Sending To)")
Label6.Text = ("Message (email message)
Label7.Text = ("Subject (email subject)")
End Sub7. Create two buttons one called "Send" and another called "closed", you can put them side by side at the bottom of the form
8. Double click on the send button, then input the code between the "private Sub Button1_Click"
Code
Try
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential(TextBox3.Text, TextBox4.Text) 'email address details
Smtp_Server.Port = TextBox2.Text 'Port input
Smtp_Server.EnableSsl = True
Smtp_Server.Host = TextBox1.Text 'SMTP Details
e_mail = New MailMessage()
e_mail.From = New MailAddress(TextBox3.Text) 'email address sending from
e_mail.To.Add(TextBox7.Text) 'Email address getting sent to
e_mail.Subject = TextBox5.Text 'email subject
e_mail.IsBodyHtml = False
e_mail.Body = TextBox6.Text 'email message
Smtp_Server.Send(e_mail)
MsgBox("Message Sent!")
Catch error_t As Exception
MsgBox("There was an error!", vbCritical, "Fatal error")
End Try
End Sub9. Next double click on the "close" button, the input the following code between "Private Sub Button2_Click"
Code
Dim response As MsgBoxResult
response = MsgBox("Do you want to close SMTP Mailer", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirm")
If response = MsgBoxResult.Yes Then
Me.Dispose()
ElseIf response = MsgBoxResult.No Then
Exit Sub
End If
End SubEXTRA NOTES:
- For text box 6 and 7 make them multiple input so you can put in multiple email address and also be able to type a email.
- You don't have to keep this layout you can change it how ever you want.
- You can also change the label names in there property's, you don't have to have it coded like at the start.
- As I stated at the start this is a very basic SMTP Mailer and is just for beginners to learn.
- This can be used as a mass mailer (bulk mailer) if user wanted to.
If you have any questions at all feel free to ask, this is for educational purposes.
Hope you all like it.

