Sending more than one attachment

  • Thread starter Dragos Marian Barbu
  • Start date
D

Dragos Marian Barbu

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(Object 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)
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top