#Region " Imports "
Imports System.Net.Mail
Imports Statistics.AppException
#End Region
Public Class Cdo
#Region " Instance Fields "
Shared _msgAttachments As String = String.Empty
Shared _msgBCC As String = String.Empty
Shared _msgBody As String = String.Empty
Shared _msgCC As String = String.Empty
Shared _defaultAddress As String = "ASCAQH.Helpdesk@wpafb.af.mil"
Shared _msgFrom As String = String.Empty
Shared _msgFromDisplayName As String = String.Empty
Shared _msgSubject As String = String.Empty
Shared _msgTo As String = String.Empty
#End Region
#Region " Properties "
Public Shared Property msgAttachments() As String
Get
Return _msgAttachments
End Get
Set(ByVal value As String)
_msgAttachments = value
End Set
End Property
Public Shared Property msgBCC() As String
Get
Return _msgBCC
End Get
Set(ByVal value As String)
_msgBCC = value
End Set
End Property
Public Shared Property msgBody() As String
Get
Return _msgBody
End Get
Set(ByVal value As String)
_msgBody = value
End Set
End Property
Public Shared Property msgCC() As String
Get
Return _msgCC
End Get
Set(ByVal value As String)
_msgCC = value
End Set
End Property
Public Shared Property msgFrom() As String
Get
Return _msgFrom
End Get
Set(ByVal value As String)
_msgFrom = value
End Set
End Property
Public Shared Property msgFromDisplayName() As String
Get
Return _msgFromDisplayName
End Get
Set(ByVal value As String)
_msgFromDisplayName = value
End Set
End Property
Public Shared Property msgSubject() As String
Get
Return _msgSubject
End Get
Set(ByVal value As String)
_msgSubject = value
End Set
End Property
Public Shared Property msgTo() As String
Get
Return _msgTo
End Get
Set(ByVal value As String)
_msgTo = value
End Set
End Property
#End Region
#Region " Methods "
Public Shared Sub Send()
Dim Message As MailMessage = New MailMessage
With Message
If Not _msgAttachments.Equals(String.Empty) Then
Dim fileName As String
Dim fileArray() As String = _msgAttachments.Split(";")
For Each fileName In fileArray
.Attachments.Add(New Attachment(fileName.Trim()))
Next
End If
If Not _msgBCC.Equals(String.Empty) Then
Dim bccAddress As String
Dim bccArray() As String = _msgBCC.Split(";")
For Each bccAddress In bccArray
.Bcc.Add(New MailAddress(bccAddress.Trim()))
Next
End If
If Not _msgBody.Equals(String.Empty) Then
.Body = _msgBody
End If
If Not _msgCC.Equals(String.Empty) Then
Dim ccAddress As String
Dim ccArray() As String = _msgBCC.Split(";")
For Each ccAddress In ccArray
.CC.Add(New MailAddress(ccAddress.Trim()))
Next
End If
If Not _msgFrom.Equals(String.Empty) Then
If Not _msgFromDisplayName.Equals(String.Empty) Then
.From = New MailAddress(_msgFrom.Trim(), _msgFromDisplayName.Trim())
Else
.From = New MailAddress(_msgFrom.Trim())
End If
Else
.From = (New MailAddress(_defaultAddress.Trim()))
End If
If Not _msgSubject.Equals(String.Empty) Then
.Subject = _msgSubject
End If
If Not _msgTo.Equals(String.Empty) Then
Dim toAddress As String
Dim toArray() As String = _msgTo.Split(";")
For Each toAddress In toArray
.To.Add(New MailAddress(toAddress.Trim()))
Next
Else
.To.Add(New MailAddress(_defaultAddress.Trim()))
End If
'TODO:
'.DeliveryNotificationOptions - DeliveryNotificationOptions
'.Priority - mailPriority
'.ReplyTo - mailAddress
'.Sender - mailAddress
End With
TransmitUnsigned(Message)
End Sub
Private Shared Sub TransmitUnsigned(ByVal message As MailMessage)
Try
Dim client As SmtpClient = New SmtpClient()
client.Send(message)
Catch ex As Exception
Throw New AppException("ERROR CDO1 - Error returned from mail relay: ", ex)
HttpContext.Current.Response.Write("
CDO ERROR: " & ex.Message)
HttpContext.Current.Response.End()
End Try
End Sub
Private Shared Sub TransmitSigned(ByVal message As MailMessage)
'Temporary for testing:
HttpContext.Current.Response.Write("
Message BCC: " & message.Bcc.ToString())
HttpContext.Current.Response.Write("
Message Body: " & message.Body.ToString())
HttpContext.Current.Response.Write("
Message CC: " & message.CC.ToString())
HttpContext.Current.Response.Write("
Message From: " & message.From.ToString())
HttpContext.Current.Response.Write("
Message Subject: " & message.Subject.ToString())
HttpContext.Current.Response.Write("
Message To: " & message.To.ToString())
HttpContext.Current.Response.End()
End Sub
#End Region
End Class
'Web.Config (Need working credentials):
'
'
'
'
'
'
'