G
Guest
Hi,
I am having some trouble using the MailMessage object to send an email with
more than one attachment.
I am working on a web based application where a user can submit information,
along with a number of files. The information, including the file is stored
in the database, and an email is sent with the information and any files that
were submitted are attached. The system works fine when a user makes a
submission that has no attachments, and also works when only one file is
attached. However when a second, or subsequent files are attached, I get the
following exception (with the inner exceptions below it).
Could not access 'CDO.Message' object.
Exception has been thrown by the target of an invocation.
Unspecified error
When a user submits a file, it is stored directly to the database, and when
the email is going to be sent, it is retreived from the database and saved in
a temp directory that sits in the application directory. They are then
defined attached to my mail message object using this code:
For Each str In Split(fileNames, "$")
If str <> "" Then
Dim emailAttachment As New MailAttachment(AppSettings("TempDir") &
"\" & str)
_emailMessage.Attachments.Add(emailAttachment)
End If
Next
The exception is thrown when i use the smtpmail.send method. Here is the
code that i am using to create the rest of the MailMessage properties:
_emailMessage.Body = strBody
'Set the rest of the properties for the email message
_emailMessage.BodyFormat = MailFormat.Html
_emailMessage.From = _emailRequest.SubmitterEmail
_emailMessage.To = "(e-mail address removed)-real"
_emailMessage.Subject = "New information has been submitted"
and is then sent with:
SmtpMail.SmtpServer = AppSettings("EmailRelay")
SmtpMail.Send(_emailMessage)
Now the bit i don't get is why it is only working with one or less
attachments. I have checked the settings on the IIS SMTP virtual service, and
there is nothign that would stop it from sending more than one attachment,
and the obvious reson i can't troubleshoot this on my own is the unpsecified
error at the bottom of my exception list. Has anyone else had a similar
problem? Any assistance on this would be great!
I am having some trouble using the MailMessage object to send an email with
more than one attachment.
I am working on a web based application where a user can submit information,
along with a number of files. The information, including the file is stored
in the database, and an email is sent with the information and any files that
were submitted are attached. The system works fine when a user makes a
submission that has no attachments, and also works when only one file is
attached. However when a second, or subsequent files are attached, I get the
following exception (with the inner exceptions below it).
Could not access 'CDO.Message' object.
Exception has been thrown by the target of an invocation.
Unspecified error
When a user submits a file, it is stored directly to the database, and when
the email is going to be sent, it is retreived from the database and saved in
a temp directory that sits in the application directory. They are then
defined attached to my mail message object using this code:
For Each str In Split(fileNames, "$")
If str <> "" Then
Dim emailAttachment As New MailAttachment(AppSettings("TempDir") &
"\" & str)
_emailMessage.Attachments.Add(emailAttachment)
End If
Next
The exception is thrown when i use the smtpmail.send method. Here is the
code that i am using to create the rest of the MailMessage properties:
_emailMessage.Body = strBody
'Set the rest of the properties for the email message
_emailMessage.BodyFormat = MailFormat.Html
_emailMessage.From = _emailRequest.SubmitterEmail
_emailMessage.To = "(e-mail address removed)-real"
_emailMessage.Subject = "New information has been submitted"
and is then sent with:
SmtpMail.SmtpServer = AppSettings("EmailRelay")
SmtpMail.Send(_emailMessage)
Now the bit i don't get is why it is only working with one or less
attachments. I have checked the settings on the IIS SMTP virtual service, and
there is nothign that would stop it from sending more than one attachment,
and the obvious reson i can't troubleshoot this on my own is the unpsecified
error at the bottom of my exception list. Has anyone else had a similar
problem? Any assistance on this would be great!