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 = "me@mydomain.com;
msg.To = "so*****@somewhere.com";
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 = "me@mydomain.com;
msg.To = "so*****@somewhere.com";
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 = "me@mydomain.com;
msg.To = "so*****@somewhere.com";
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 4 8342
Try to use encoding parameter in MailAttachment constructor.
"Trond A. S. Andersen" <ts*@scandpower.no> wrote in message
news:08****************************@phx.gbl... 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 = "me@mydomain.com; msg.To = "so*****@somewhere.com"; 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 = "me@mydomain.com; msg.To = "so*****@somewhere.com"; 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 = "me@mydomain.com; msg.To = "so*****@somewhere.com"; 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
Try to use encoding parameter in MailAttachment constructor.
"Trond A. S. Andersen" <ts*@scandpower.no> wrote in message
news:08****************************@phx.gbl... 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 = "me@mydomain.com; msg.To = "so*****@somewhere.com"; 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 = "me@mydomain.com; msg.To = "so*****@somewhere.com"; 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 = "me@mydomain.com; msg.To = "so*****@somewhere.com"; 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
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 -----Original Message----- Try to use encoding parameter in MailAttachment
constructor.
"Trond A. S. Andersen" <ts*@scandpower.no> wrote in
messagenews:08****************************@phx.gbl... 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 = "me@mydomain.com; msg.To = "so*****@somewhere.com"; 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 = "me@mydomain.com; msg.To = "so*****@somewhere.com"; 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 = "me@mydomain.com; msg.To = "so*****@somewhere.com"; 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
.
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 -----Original Message----- Try to use encoding parameter in MailAttachment
constructor.
"Trond A. S. Andersen" <ts*@scandpower.no> wrote in
messagenews:08****************************@phx.gbl... 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 = "me@mydomain.com; msg.To = "so*****@somewhere.com"; 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 = "me@mydomain.com; msg.To = "so*****@somewhere.com"; 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 = "me@mydomain.com; msg.To = "so*****@somewhere.com"; 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
. This discussion thread is closed Replies have been disabled for this discussion. Similar topics
reply
views
Thread by Trond A. S. Andersen |
last post: by
|
5 posts
views
Thread by Chris Thunell |
last post: by
|
3 posts
views
Thread by Brian Farnhill (MCP VB.NET) |
last post: by
|
1 post
views
Thread by theWizard1 |
last post: by
|
2 posts
views
Thread by Brad |
last post: by
|
4 posts
views
Thread by David C |
last post: by
|
5 posts
views
Thread by =?Utf-8?B?SmltSm9i?= |
last post: by
|
11 posts
views
Thread by Ed Bitzer |
last post: by
|
2 posts
views
Thread by Prefers Golfing |
last post: by
| | | | | | | | | | |