Created
December 10, 2013 02:14
-
-
Save bmc08gt/7884762 to your computer and use it in GitHub Desktop.
Simple Mail SmtpServer Form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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