Invalid mail attachment in C#

F

Fraser S

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.sendXMLResponse(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);
 

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

Similar Threads


Top