Listing 1

Imports System.Web.Mail
Imports System.Text

Namespace PostalSystem

Public Class PostOffice

Private _Message As MailMessage

Public Sub New(ByVal recipients As ArrayList, _
ByVal from As String, _
ByVal subject As String)

_Message = New MailMessage()
_Message.To = BuildRecipientList(recipients)
_Message.From = from
_Message.Subject = subject

End Sub

Public Sub New(ByVal recipients As String, _
ByVal from As String, _
ByVal subject As String)

_Message = New MailMessage()
_Message.To = recipients
_Message.From = from
_Message.Subject = subject

End Sub

Public Sub New(ByVal recipients As ArrayList, _
ByVal from As String, _
ByVal subject As String, _
ByVal format As MailFormat)

Me.New(recipients, from, subject)
_Message.BodyFormat = format

End Sub

Public Sub New(ByVal recipients As String, _
ByVal from As String, _
ByVal subject As String, _
ByVal format As MailFormat)

Me.New(recipients, from, subject)
_Message.BodyFormat = format

End Sub

Protected Function BuildRecipientList _
(ByVal recipients As ArrayList) As String

Dim recipient As String
Dim recipientList As New StringBuilder()

For Each recipient In recipients
recipientList.Append(recipient & ";")
Next

Return recipientList.ToString()

End Function

Public Sub SendMail(ByVal mail As IMailable)

Try

_Message.Body = mail.ToMessage()
SmtpMail.Send(_Message)

Catch ex As Exception
'TODO: Implement Exception Handling

End Try

End Sub

Public ReadOnly Property Message() As MailMessage
Get
Return _Message
End Get
End Property

End Class

End Namespace