Recently I tried to develop a function to help me sending e-mail messages
with more than one attachment. Everything is working OK when I am sebding
messages with one attachment, but when I try to send more than one file as
attachment I get the following error:
-------- Error -----------------
Could not access 'CDO.Message' object.
at System.Web.Mail.LateBoundAccessHelper.CallMethod(O bject obj, String
methodName, Object[] args) at System.Web.Mail.CdoSysHelper.Send(MailMessage
message) at System.Web.Mail.SmtpMail.Send(MailMessage message) at
GlendaleInfo.ReadFile.SendMail(String SendTo, String SentFrom, String
MessageSubject, String MessageBody, MailFormat MessageType, String
MailAttachments) in ....
----------------> End Error
Here is my code which tries to attach the the files and send the message:
' Creating the email object
Dim oMail As MailMessage = New MailMessage
' Creating the attachment object
'*********************************************
' Checking if there is some attachments
'*********************************************
If MailAttachments <> "" Then
Dim FilesToAttach() As String
Dim j As Integer
FilesToAttach = Split(MailAttachments, ",")
For j = 0 To UBound(FilesToAttach)
' Create the mail attachment
Dim oMailAttachment As MailAttachment = New
MailAttachment(FilesToAttach(j))
' Adding the attachment/s to the email message
oMail.Attachments.Add(oMailAttachment)
Next
SmtpMail.SmtpServer = ""
End If
' Create de message
'oMail = New MailMessage
oMail.To = SendTo
oMail.From = SentFrom
' Body format
oMail.BodyFormat = MessageType
oMail.Priority = MailPriority.High
'Message subject
oMail.Subject = MessageSubject
' Message body
oMail.Body = MessageBody
'sending e message
SmtpMail.Send(oMail)