AbdulMuttaqin

Mailer [VB.NET]

Oct 13th, 2017
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.92 KB | None | 0 0
  1. Imports System.Net.Mail
  2. Public Class Form1
  3.     Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
  4.         OpenFileDialog1.ShowDialog()
  5.     End Sub
  6.     Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
  7.         attach.Text$ = OpenFileDialog1.FileName
  8.     End Sub
  9.     Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  10.         BackgroundWorker1.RunWorkerAsync()
  11.     End Sub
  12.     Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
  13.         Using mail As New MailMessage
  14.             mail.From = New MailAddress("Your Mail/Mail you want to send from")
  15.             mail.To.Add(destination.Text$)
  16.             mail.Body = body.Text$
  17.             If Not OpenFileDialog1.FileName = vbNullString Then
  18.                 Dim attach As New Attachment(OpenFileDialog1.FileName)
  19.                 mail.Attachments.Add(attach)
  20.             End If
  21.             mail.Subject = subject.Text$
  22.             mail.Priority = mail.Priority.Normal
  23.             Using SMTP As New SmtpClient
  24.                 SMTP.EnableSsl = True
  25.                 SMTP.Port = "587"
  26.                 SMTP.Host = "smtp.gmail.com"
  27.                 SMTP.Credentials = New Net.NetworkCredential("Your Mail/Mail you want to send from", "Your Password")
  28.                 SMTP.Send(mail)
  29.             End Using
  30.         End Using
  31.     End Sub
  32.     Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
  33.         destination.Clear()
  34.         subject.Clear()
  35.         attach.Clear()
  36.         body.Clear()
  37.         MsgBox("Email has been sent successfully!, MsgBoxStyle.Information)
  38.    End Sub
  39. End Class
Add Comment
Please, Sign In to add comment