I'm trying to attach a PDF attachment to an email being sent with System.Net.Mail. The attachment-adding part looks like this:
using (MemoryStream pdfStream = new MemoryStream())
{
pdfStream.Write(pdfData, 0, pdfData.Length);
Attachment a = new Attachment(pdfStream,
string.Format("Receipt_{0}_{1}.pdf", jobId, DateTime.UtcNow.ToString("yyyyMMddHHmm")));
msg.Attachments.Add(a);
SmtpClient smtp = new SmtpClient(serverName, port);
smtp.Credentials = new NetworkCredential(fromEmailName, fromEmailPassword);
smtp.Send(msg);
}
The problem is that the attachment gets corrupted on the other end. I found some discussion of this problem here, however the solution mentioned on that page used System.Web.Mail.MailAttachment, which was made obsolete in .NET 2.0.
I've tried changing the TransferEncoding in the Attachment class (which replaces MailAttachment), but had no luck. Has anyone solved this on .NET 2.0?