我必须解码以下代码,然后将其作为PDF附加到C#的电子邮件中。
using (var stream = new MemoryStream())
using (var writer = new StreamWriter(stream)) // using UTF-8 encoding by default
using (var smtpClient = new SmtpClient("localhost", 25))
using (var message = new MailMessage("Mail@mail.com", "me@mail.com", "Just testing", "See attachment..."))
{
writer.WriteLine("0x255044462D312E340A25E2E3CFD30A332030206F626A203C3C2F4[...]");
writer.Flush();
stream.Position = 0; // read from the start of what was written
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType(System.Net.Mime.MediaTypeNames.Application.Pdf);
Attachment attach = new Attachment(stream, ct);
message.Attachments.Add(new Attachment(stream, "filename.pdf", "application/pdf"));
smtpClient.Port = 25;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Host = ConfigurationManager.AppSettings["MailHost"];
smtpClient.Send(message);
}
已发送电子邮件,但是当我要打开它时,它告诉我文件已损坏。
有人对PDF文件进行了这种解码吗?