'Set the HostName
Dim host As String = "host name or ip address"
'Set the email information
Dim [From] As String = "[email protected]"
Dim [To] As String = "[email protected]"
Dim Subject As String = "test2"
Dim Body As String = "Body"
'Create a new MailMessage, specifying who it is From and who it is going To
' and set the Subject and Body
Dim Email As New System.Net.Mail.MailMessage([From], [To])
Email.Subject = Subject
Email.Body = Body
'Create a new SmtpClient
Dim mailClient As New System.Net.Mail.SmtpClient()
mailClient.Host = host
Try
'Attempt to send the email, show any exceptions below
mailClient.Send(Email)
MsgBox("Email Sent!")
Catch ex As Exception
MessageBox.Show("Unable to send email, because the following error has occurred:" & _
vbCrLf & vbCrLf & _
ex.Message, _
"Error sending email", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Email.Dispose()
mailClient = Nothing
GC.Collect()
|