Download Visual Basic:
http://www.microsoft.com/visualstudio/en-us
Imports System.Net.Mail
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If msgTo.Text = "" Or msgFrom.Text = "" Or msgSubject.Text = "" Or msgBody.Text = "" Or smtpHost.Text = "" Or smtpPort.Text = "" Then
MsgBox("You must fill out everything!", MsgBoxStyle.Information, "Error")
Exit Sub
End If
On Error GoTo msgError
Dim smtpServer As New SmtpClient()
Dim mail As New MailMessage()
smtpServer.Credentials = New Net.NetworkCredential("email", "password")
smtpServer.Port = smtpPort.Text
smtpServer.Host = smtpHost.Text
If SSL.Checked = True Then
smtpServer.EnableSsl = True
Else
smtpServer.EnableSsl = False
End If
smtpServer.EnableSsl = SSL.Checked
mail = New MailMessage()
mail.From = New MailAddress(msgFrom.Text)
mail.To.Add(msgTo.Text)
mail.Subject = msgSubject.Text
mail.Body = msgBody.Text
smtpServer.Send(mail)
MsgBox("Email was sent to:" & msgTo.Text)
Exit Sub
msgError:
MsgBox("Couldn't send email, please make sure the SMTP Settings are correct.", MsgBoxStyle.Critical, "Error")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
smtpHost.Text = "smtp.live.com"
End Sub
End Class
No comments:
Post a Comment