472,125 Members | 1,428 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,125 software developers and data experts.

Error when attaching multiple files (System.web.mail)

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 = "my*****@code-example.not-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!
Nov 19 '05 #1
3 2149
Hi Brian,

Try these two things:

1. Try to give permissions to c:\Documents and Settings\ASPNET\Local
Settings folder on your machine to the authenticated domain user account.

2. Try to give permissions to ASPNET user account on the local folder where
you are storing your attachments.

Since you are able to sent the mail so it looks all the problem because of
permissions, you just double check them. Also check whether the indexing
services is running on your machine sometimes it locks the local folder to
which its indexing and unfortunately at that moment itself your app try to
write into that! Try to stop indexing services and then try you stuff.

Hope this helps.

"Brian Farnhill (MCP VB.NET)" wrote:
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 = "my*****@code-example.not-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!

Nov 19 '05 #2
Hi Hitesh,

When you say give permissions to the authenticated domain user account, do
you mean the account the the email is being sent from? The emails are set to
come from the suer that is using the form, the application uses
impersonation, set in the web.config file with the following tags:

<authentication mode="Windows" />
<identity impersonate="true" />
<authorization>
<deny users="?" />
</authorization>

I'm not sure that it is anything to do with permissions on a folder, as the
email will still send with one attachment, its just when i add a second or
more attachments that it fails, but I'll go give that a go, as soon as the
guys that manage the servers let me near the box again! I'll let you know how
I go

- B

"Hitesh" wrote:
Hi Brian,

Try these two things:

1. Try to give permissions to c:\Documents and Settings\ASPNET\Local
Settings folder on your machine to the authenticated domain user account.

2. Try to give permissions to ASPNET user account on the local folder where
you are storing your attachments.

Since you are able to sent the mail so it looks all the problem because of
permissions, you just double check them. Also check whether the indexing
services is running on your machine sometimes it locks the local folder to
which its indexing and unfortunately at that moment itself your app try to
write into that! Try to stop indexing services and then try you stuff.

Hope this helps.

"Brian Farnhill (MCP VB.NET)" wrote:
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 = "my*****@code-example.not-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!

Nov 19 '05 #3
Hey Hitesh,

OK, Ive tried these things, and it still doesn't work, i get the same error
details. Does anyone else have any other ideas?

- B

"Hitesh" wrote:
Hi Brian,

Try these two things:

1. Try to give permissions to c:\Documents and Settings\ASPNET\Local
Settings folder on your machine to the authenticated domain user account.

2. Try to give permissions to ASPNET user account on the local folder where
you are storing your attachments.

Since you are able to sent the mail so it looks all the problem because of
permissions, you just double check them. Also check whether the indexing
services is running on your machine sometimes it locks the local folder to
which its indexing and unfortunately at that moment itself your app try to
write into that! Try to stop indexing services and then try you stuff.

Hope this helps.

"Brian Farnhill (MCP VB.NET)" wrote:
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 = "my*****@code-example.not-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!

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Peter Frost | last post: by
1 post views Thread by Peter van der Goes | last post: by
6 posts views Thread by Joachim | last post: by
9 posts views Thread by JTrigger | last post: by
2 posts views Thread by James | last post: by
dmjpro
6 posts views Thread by dmjpro | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.