Could not access 'CDO.Message' object.

M

MattB

I've taken some working code from a vb clas library that was a part of a web
application and put it into a stand alone class library so I can reuse it
from other applications. I'm using some code (pasted below) to send email
that uses the mail.mailmessage object. It compiles ok, and debugs ok until
the mail is supposed to be sent and it throws an exception, whitht e
message: "Could not access 'CDO.Message' object.".

Can anyone suggest what I should be looking for to troubleshoot this? Code
below:
Thanks!

Matt

-----------------

Public Shared Function SendEmail _
(ByVal strTo As String, ByVal strFrom As String, ByVal strName As String,
ByVal strSubj As String, _
ByVal strBody As String, ByVal bHTML As Boolean, ByVal strSMTPServer As
String, _
Optional ByVal strCC As String = Nothing, Optional ByVal strBCC As
String = Nothing, _
Optional ByVal strSMTPuser As String = Nothing, Optional ByVal
strSMTPPass As String = Nothing, _
Optional ByVal strAttach As String = Nothing)

Dim newMail As New System.Web.Mail.MailMessage

newMail.To = strTo
newMail.From = strFrom
newMail.Subject = strSubj
newMail.Body = strBody
If Not IsNothing(strAttach) Then
Dim aAttachments() As String, i As Int16
aAttachments = strAttach.Split(",")
For i = aAttachments.GetLowerBound(0) To
aAttachments.GetUpperBound(0)
If File.Exists(aAttachments(i)) Then
Dim oAttachment As New MailAttachment(aAttachments(i))
newMail.Attachments.Add(oAttachment)
End If
Next
End If

newMail.Cc = strCC
newMail.Bcc = strBCC
If Not IsNothing(strSMTPuser) Then
newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",
strSMTPuser)
newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",
strSMTPPass)
newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",
"1")
Else
newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",
"0")
End If

If bHTML Then
newMail.BodyFormat = System.Web.Mail.MailFormat.Html
Else
newMail.BodyFormat = System.Web.Mail.MailFormat.Text
End If

SmtpMail.SmtpServer = strSMTPServer

Try
SmtpMail.Send(newMail)
Return "OK :"
Catch ex As Exception
'copy message to string for debugging - not really used anywhere
Dim strMessage As String = ex.Message
Return "ERR: " & strMessage
End Try

newMail = Nothing
End Function
 
M

MattB

It did. My code worked, but I was having an authentication problem (wish it
woud say so).

So if anyone needs some emailing vb code, help yourself!

Thanks!
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top