By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,995 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,995 IT Pros & Developers. It's quick & easy.

Invalid mail attachment in C#

P: n/a
Hi, I am receiving an invalid mail Attachment error when trying to
send an attachment using System.Web.Mail. I have read other posts on
these errors and have since checked that the asp.net account has
permissions to access the file and of course that it is there. I am
also running the program on the same machine that the file is stored.
I have included the full error message below as well as the code. Any
help you could give on this issued would be greatly appreciated.

Error message

Invalid mail attachment ''.
System.Web at System.Web.Mail.MailAttachment.VerifyFile()
at System.Web.Mail.MailAttachment..ctor(String filename, MailEncoding
encoding)
at WindowsApplication1.LocalResponseEmail.sendXMLResp onse(String
toAddress)

Code

MailMessage mail = new MailMessage();
mail.From = "email address";
mail.To = "email address";
mail.Subject = "txt";
mail.Body = "text";
mail.BodyFormat = MailFormat.Text;

mail.Attachments.Add(new MailAttachment(filename));

System.Web.Mail.SmtpMail.SmtpServer = "mail server name";
System.Web.Mail.SmtpMail.Send(mail);
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
What is the value of filename? Does it contain the path?

"Fraser S" <fs***@btinternet.com> wrote in message
news:25*************************@posting.google.co m...
Hi, I am receiving an invalid mail Attachment error when trying to
send an attachment using System.Web.Mail. I have read other posts on
these errors and have since checked that the asp.net account has
permissions to access the file and of course that it is there. I am
also running the program on the same machine that the file is stored.
I have included the full error message below as well as the code. Any
help you could give on this issued would be greatly appreciated.

Error message

Invalid mail attachment ''.
System.Web at System.Web.Mail.MailAttachment.VerifyFile()
at System.Web.Mail.MailAttachment..ctor(String filename, MailEncoding
encoding)
at WindowsApplication1.LocalResponseEmail.sendXMLResp onse(String
toAddress)

Code

MailMessage mail = new MailMessage();
mail.From = "email address";
mail.To = "email address";
mail.Subject = "txt";
mail.Body = "text";
mail.BodyFormat = MailFormat.Text;

mail.Attachments.Add(new MailAttachment(filename));

System.Web.Mail.SmtpMail.SmtpServer = "mail server name";
System.Web.Mail.SmtpMail.Send(mail);

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.