Question about Managed CDOSYS.DLL .Net wrapper

T

Tobias

I have a question in relation to creating and sending CDO
mail message objects using the managed wrapper namespace
for CDOSYS.DLL in the .net framework called System.Web.Mail

Q. How come CDO methods and properties are blocked by the
Outlook Security Update, however when instaniating and
then calling the Send method on a
System.Web.Mail.MailMessage object there is no such
restriction?
In what way is the SMTP relay server service mentioned as
a property in the SMTPServer object used that skirts
around the security update that normally blocks CDO code.

I have even tried running this code in process from a DLL
within Outlook 2003 against an Exchange 2000 server and it
runs fine.
The only possible downside is no mailitem gets left in the
sent items although if this was really a problem you could
create a new mailitem object and plant it there to cover
your tracks.

Anyways a class I wrote to encapsulate creating and using
a MailMessage object is below.


Option Strict On

' Programmer : Tobias Nixon
' Refernences : CDOSYS.DLL is referenced by the managed
wrapper.
' Date : 1/12/2003

' Import System.Web.Mail .Net framework Namespace to
support Email.
Imports System.Web.Mail


' Namespace : CDOEmailMsg
Namespace CDOEmailMsg

' Public scoped Class : EmailMessage
' Provides reusable Email messsaging class component.
Public Class EmailMessage
Private Recipient As String = ""
Private Sender As String = "(e-mail address removed)"
Private EmailBody As String = ""
Private EmailSubject As String = ""
Private SMTPServerAddress As String

Public Sub New(ByVal Sndr As String _
, ByVal Recip As String _
, ByVal Body As String _
, ByVal Subject As String _
, ByVal SMTPAddr As String)
Recipient = Recip
Sender = Sndr
EmailBody = Body
EmailSubject = Subject
SMTPServerAddress = SMTPAddr

End Sub

Private Function CreateEmail() As
System.Web.Mail.MailMessage
Try

' create a new mail message
Dim oMailMsg As System.Web.Mail.MailMessage = _
New
System.Web.Mail.MailMessage

If Recipient <> "" And EmailBody <> "" Then
' Set Priority
Dim oPriority As MailPriority =
MailPriority.Normal
' Set Body Format
Dim oBodyFormat As MailFormat =
MailFormat.Html
'' Set Attachment Encoding
'Dim oEncoding As MailEncoding =
MailEncoding.Base64
' Set the properties of the Message.

With oMailMsg
.Priority = oPriority
.BodyFormat = oBodyFormat
'.Attachments =System.Collections.IList
.From = Sender
.To = Recipient
.Subject = EmailSubject
.Body = EmailBody
End With

End If

Return oMailMsg
oMailMsg = Nothing

Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try

End Function

Private Function SendEmail() As Boolean
Try
'SMTPServerAddress
Dim strSMTPAddress As String =
SMTPServerAddress
Dim oSMTP As SmtpMail
oSMTP.SmtpServer = strSMTPAddress
' return a mail message , properly formed.
Dim oMailMsg As System.Web.Mail.MailMessage =
CreateEmail()
oSMTP.Send(oMailMsg)
oSMTP = Nothing
Return True

Catch ex As Exception
Debug.WriteLine(ex.Message)
If ex Is Nothing Then
Return False
End If
End Try

End Function

Public Sub SendMail()

If SendEmail() = True Then

' Email has been sent.
Debug.WriteLine("Email sent to recipient!")

End If

End Sub

End Class
End Namespace
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top