Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

SMTP Mailer (vb.net tutorial for beginners)

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:

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 Sub
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"

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 Sub

9. 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 Sub
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.
EXTRA EXTRA NOTES:
- If you are planning to use Gmail As SMTP for bulk mailer (Max. 100 To: and 500 e-mail/day), gratz, google will ban you.
(Aug 25, 2016 03:05 PM)Zilog80 Wrote:  EXTRA EXTRA NOTES:
- If you are planning to use Gmail As SMTP for bulk mailer (Max. 100 To: and 500 e-mail/day), gratz, google will ban you.

Very true but that goes for most free email providers. They all have there own limits and if you go past then your banned. If someone was serious about sending large amounts they would probably get their own SMTP that has no limits or not so minimal
Off-topic:

MsgBox VS MessageBox.Show

http://stackoverflow.com/questions/87999...gebox-show

Personally I don't use MsgBox since 2003 (last year I coded in VB5/6)
Many if not all email filters reverse resolve your Ip to confirm your associated with the domain in the from address. Also I'm on a phone so hard to read code but Google requires you to start tls before it will talk to you. Also do you have the script dig for mx records or is that up to the user to find proper host? Not sure how the smtp client works. But really cool! You made me want to start Ms studios back up
(Aug 25, 2016 10:00 PM)Death LurkZ Wrote:  Many if not all email filters reverse resolve your Ip to confirm your associated with the domain in the from address. Also I'm on a phone so hard to read code but Google requires you to start tls before it will talk to you. Also do you have the script dig for mx records or is that up to the user to find proper host? Not sure how the smtp client works. But really cool! You made me want to start Ms studios back up

Hey thanks for the interest in it. The way it works is once you have completed it you'll have a full smtp mailer. To use it the only details you would need would be:
Email
Email password
SMTP details (example: smtp.gmail.com)
Port

And then you would be set and able to use it. I know that some times gmail will want you to change your security settings and allow it to talk to thirdparty apps but besides from that there should be no issues.
Ooohhh OK thought it was making a connection to the recipients email server and sending directly, you are actually logging in to your gmail and sending the email like outlook. That makes more sense, thanks for the share
Nice tutorial and easy...thanks for sharing
very basic solution, nice for beginners


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by Theo™May 1, 2017 11:46 AM 8 387 May 1, 2017 11:46 AM
Last Post: ZipBag
[C] by Kashmiri HunterMar 11, 2017 08:48 AM 4 374 Mar 11, 2017 08:48 AM
Last Post: Praet0rian
[C#] by WakkaSep 25, 2016 05:06 PM 10 303 Sep 25, 2016 05:06 PM
Last Post: Wakka