System.Web.Mail.MailMessage attachment problem

  • Thread starter Trond A. S. Andersen
  • Start date
T

Trond A. S. Andersen

Hi, all!

I'm trying to use the System.Web.Mail. "package" combinded
with System.Web.Mail.SmtpMail in order to send MS Excel
spreadsheets attached to mail messages. However, sending
one single spreadsheet attachment per message, seems to be
causing som kind of corruption of the attachment, while
several spreadsheets per works just fine. Consider the
following three snippets of C# code:

// Sample 1 ->

System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage();
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_spreadsheet.xls"));
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_other_spreadsheet.xls"));

msg.From = "(e-mail address removed);
msg.To = "(e-mail address removed)";
msg.Subject = "TWO Excel spreadsheets attached;

System.Web.Mail.SmtpMail.SmtpServer = "some_smtp_server";
System.Web.Mail.SmtpMail.Send(msg);


// Sample 2 ->

System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage();
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_spreadsheet.xls"));

msg.From = "(e-mail address removed);
msg.To = "(e-mail address removed)";
msg.Subject = "TWO Excel spreadsheets attached;

System.Web.Mail.SmtpMail.SmtpServer = "some_smtp_server";
System.Web.Mail.SmtpMail.Send(msg);

// Sample 3 ->

System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage();
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_other_spreadsheet.xls"));

msg.From = "(e-mail address removed);
msg.To = "(e-mail address removed)";
msg.Subject = "TWO Excel spreadsheets attached;

System.Web.Mail.SmtpMail.SmtpServer = "some_smtp_server";
System.Web.Mail.SmtpMail.Send(msg);


Using the code in Sample 1, both attatchments can be
opened by Excel without any problem, as they arrive at the
receiving end.

Using the code in Sample 2 or Sample 3, however, NEITHER
of the attachments, which happens to be the EXACT same two
Excel spreadsheets as in Sample1, can be opened by the
receipient using Excel. Any ettemt two open them results
in either a "The document is corrupt and cannot be opened.
To try an repair..." error message or a " cannot
be accessed. The file may be read-only, or..." error
message. If any of you have an idea what's causing this
problem, and maybe even a suggestion for a workaround,
your reply would be highly appreciated.

Regards, Trond
 
T

Trond A. S. Andersen

Tried that. Excel spreadsheet attachments somehow
corrupted by the System.Web.Mail/System.Web.Mail.SmtpMail
framework, no matter what encoding parameter i use.

Thanks, anyway
 

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

Top