[英]corrupted email attachments in .NET
I'm trying to attach a PDF attachment to an email being sent with System.Net.Mail. 我正在尝试将PDF附件附加到与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.
我在这里找到了一些关于这个问题的讨论,但是该页面上提到的解决方案使用的是System.Web.Mail.MailAttachment,它在.NET 2.0中已经过时了。
I've tried changing the TransferEncoding in the Attachment class (which replaces MailAttachment), but had no luck. 我已经尝试更改Attachment类中的TransferEncoding(它取代了MailAttachment),但没有运气。 Has anyone solved this on .NET 2.0?
有没有人在.NET 2.0上解决这个问题?
您是否尝试在创建附件之前执行pdfStream.Seek(0,SeekOrigin.Begin)
以将流重置为开头?
Have you checked to make sure that the PDF document isn't already corrupted in the pdfData array? 您是否检查过以确保pdfData数组中的PDF文档尚未损坏? Try writing that to a file then opening it.
尝试将其写入文件然后打开它。
Cheers 干杯
Kev 千电子伏
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.