0 [Vb.net]Email Sender Using Smtp Client [Source Code]

By Doing This You Need :-
  • Textboxs
  • Textbox1 For Email
  • Textbox2 for Password
  • Textbox3 for Subject
  • Textbox4 for Receiver
  • Richtextbox for Message Body
  • Listbox for Attachments
  • Buttons
  • Button1 for Selecting the Attachments
  • Button2 for Send

You need to Add the OpenFiledialog from Toolbar

Our Imports :-

Code:
Imports System.Net.Mail

Let's the Coding Part :-
Click the Button1 And add this Code :-(This will Open the OpenFiledialog)

Code:
OpenFileDialog1.ShowDialog()

After that Add this Code :- (This will Show the Files in ListBox)

Code:
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
        For Each track As String In OpenFileDialog1.FileNames
            ListBox1.Items.Add(track)
        Next
    End Sub

Click the Button2 And Add this code :-(This Will Send the Message)

Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            Dim Mail As New MailMessage
            Mail.Subject = (TextBox3.Text)
            Mail.To.Add(TextBox4.Text)
            Mail.From = New MailAddress(TextBox1.Text)
            Mail.Body = (RichTextBox1.Text)
            For counter = 0 To ListBox1.Items.Count - 1
                Dim Attach As Net.Mail.Attachment = New Net.Mail.Attachment(ListBox1.Items(counter))
                Mail.Attachments.Add(Attach)
            Next
            Dim SMTP As New SmtpClient("smtp.gmail.com")
            SMTP.EnableSsl = True
            SMTP.Credentials = New System.Net.NetworkCredential(TextBox1.Text, TextBox2.Text)
            SMTP.Port = 587
            SMTP.Send(Mail)
            MsgBox("Message Sended Successfully To " & (TextBox4.Text), MsgBoxStyle.Information, "Email SMTP Client")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

Note:-

Code:
I Used the Gmail Smtp CLient
For Live = smtp.live.com
For Aol = smtp.uk.aol.com
For Yahoo = plus.smtp.mail.yahoo.com

Note:-

Code:
Put the Code in Timer1_trick Made It Email Bomber

Happy Coding

No comments:

Post a Comment