New User wrote:
Hi,
I have a PDF file that I am trying to send as an attachment through a C#
program. Even though the PDF file can be opened by itself, sometimes the
same
file cannot be opened as an attachment. If I try and open the original PDF
file I have no problems.
I have used System.Web.Mail .MailMessage to create an
email and an SMTPMail object to send the mail.
I tried to change the encoding to Base64 but even that has not helped. There
are still ocassions when I am unable to open the attachment.
Has anybody experienced this problem or do you have any suggestions .
Thanks!!
In my experience, sometimes the "System.Web.Mai l" will use a incorrect
attachment encoding even you had set it to "Base64". It seems the
problem is related to some version of "CDO" object installed in the
system by other application(e.g . MS office).
I solve the problem to force the encoding by changing the mail header.
MailMessage message = new MailMessage();
....
MailAttachment attach;
attach = new MailAttachment( file,MailEncodi ng.Base64);
message.Attachm ents.Add(attach );
....
//-> add this line
message.Headers .Add("Content-Transfer-Encoding","base 64");
....
--
Jacky Kwok
jacky@alumni_DO T_cuhk_DOT_edu_ DOT_hk
jacky@compose_D OT_com_DOT_hk