Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Net.Mail
- Public Class Form1
- Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
- OpenFileDialog1.ShowDialog()
- End Sub
- Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
- attach.Text$ = OpenFileDialog1.FileName
- End Sub
- Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
- BackgroundWorker1.RunWorkerAsync()
- End Sub
- Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
- Using mail As New MailMessage
- mail.From = New MailAddress("Your Mail/Mail you want to send from")
- mail.To.Add(destination.Text$)
- mail.Body = body.Text$
- If Not OpenFileDialog1.FileName = vbNullString Then
- Dim attach As New Attachment(OpenFileDialog1.FileName)
- mail.Attachments.Add(attach)
- End If
- mail.Subject = subject.Text$
- mail.Priority = mail.Priority.Normal
- Using SMTP As New SmtpClient
- SMTP.EnableSsl = True
- SMTP.Port = "587"
- SMTP.Host = "smtp.gmail.com"
- SMTP.Credentials = New Net.NetworkCredential("Your Mail/Mail you want to send from", "Your Password")
- SMTP.Send(mail)
- End Using
- End Using
- End Sub
- Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
- destination.Clear()
- subject.Clear()
- attach.Clear()
- body.Clear()
- MsgBox("Email has been sent successfully!, MsgBoxStyle.Information)
- End Sub
- End Class
Add Comment
Please, Sign In to add comment