473,473 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Invalid mail attachment in C#

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
1 10415
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: PeterR | last post by:
I've spent weeks trying to write a function that is simple to use for sending emails with attachments, but I my programming skills are not that advanced. I've noticed a few postings in these...
2
by: bmcelhany | last post by:
Hello, I'm developing a windows service that monitors a directory (using a FileSystemWatcher) for newly created files. When a new file is created, I need to generate an e-mail and send that file...
2
by: GD | last post by:
Hi, An intranet application, with a SMTP mail function that lets users to attach files with emails by selecting files in their local computers (through a file browser component), works perfect on...
3
by: Fraser S | last post by:
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...
4
by: Reticulated Ember | last post by:
I have the following code that fails with an invalid cast exception: .... System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage(); msg.BodyFormat = MailFormat.Html; ...
1
by: theWizard1 | last post by:
The following sends my email, but the attachment is empty. The attachment should contain the data that is in the string that was created from the xmlReader. I have a stored procedure written...
1
by: William Connery | last post by:
Hi, I have a small python program with e-mail capabilities that I have pieced together from code snippets found on the internet. The program uses the smtplib module to successfully send an...
8
by: =?Utf-8?B?cm95SGU=?= | last post by:
I have a web service. It creates a email and attached a file sitting one the network drive \\servername\filename. I tried UNC format and also try to mapping drive (eg. g:\text.txt or...
0
by: Kirsten Kleist | last post by:
I have an application that creates several .csv files in a directory on the user's hard drive and then sends an email with the same .csv files as attachments. One of the users is getting an error...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.