Imports System.Net Imports System.Net.Mail
Public Class SendMessage Sub SendEmail() Dim Message As New SmtpClient Message.Host = "127.0.0.1" Message.Port = 25 Message.Send(_From, _SendTo, _Subject, _Send) End Sub
Sub SendEmail(ByVal From As String, ByVal SendTo As String, ByVal Subject As String, ByVal Body As String, ByVal Host As String, ByVal Port As String) Dim Message As New SmtpClient Message.Host = Host Message.Port = Port Message.Send(From, SendTo, Subject, Body) End Sub
Sub SendEmail(ByVal From As String, ByVal SendTo As String, ByVal Subject As String, ByVal Body As String, ByVal Host As String, ByVal Port As Int32, ByVal UserName As String, ByVal Password As String) 'create the mail message Dim mail As New MailMessage() Dim smtp As New SmtpClient 'set the addresses mail.From = New MailAddress(From) mail.To.Add(SendTo)
'set the content mail.Subject = Subject mail.Body = Body
'send the message If Port = 25 Then smtp = New SmtpClient(Host, 25) Else smtp = New SmtpClient(Host, Port) End If
'to authenticate we set the username and password properites on the SmtpClient smtp.Credentials = New NetworkCredential(UserName, Password) smtp.Send(mail) End Sub
Private _From As String Private _SendTo As String Private _Subject As String Private _Body As String Private _Send As String Private _Host As String Private _Port As String
Public Property Send() As String Get Return _Send End Get Set(ByVal value As String) _Send = value End Set End Property
Public Property From() As String Get Return _From End Get Set(ByVal value As String) _From = value End Set End Property
Public Property SendTo() As String Get Return _SendTo End Get Set(ByVal value As String) _SendTo = value End Set End Property
Public Property Subject() As String Get Return _Subject End Get Set(ByVal value As String) _Subject = value End Set End Property
Public Property Body() As String Get Return _Body End Get Set(ByVal value As String) _Body = value End Set End Property End Class |