Skip to content

Instantly share code, notes, and snippets.

@bmc08gt
Created December 10, 2013 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmc08gt/7884762 to your computer and use it in GitHub Desktop.
Save bmc08gt/7884762 to your computer and use it in GitHub Desktop.
Simple Mail SmtpServer Form
Imports System.Net.Mail
Public Class MailForm
' Email contents
Dim toEmail, subject, textBody As String
' Email credentials
Dim fromEmail, password As String
Private Sub SendButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SendButton.Click
toEmail = toEmailTextBox.Text
subject = subjectTextBox.Text
textBody = textBodyRichTextBox.Text
fromEmail = EmailTextBox.Text
password = PasswordTextBox.Text
Try
Dim smtpServer As New SmtpClient
Dim email As New MailMessage()
smtpServer.UseDefaultCredentials = False
smtpServer.Credentials =
New Net.NetworkCredential(fromEmail, password)
smtpServer.Port = 587
smtpServer.EnableSsl = True
smtpServer.Host = "smtp.gmail.com"
email = New MailMessage()
email.From = New MailAddress(fromEmail)
email.To.Add(toEmail)
email.Subject = subject
email.IsBodyHtml = False
email.Body = textBody
smtpServer.Send(email)
MsgBox("Mail Sent")
Catch ex As Exception
MsgBox("Error")
End Try
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment