在C#中使用PDFDocument发送没有文件名的邮件

问题描述 投票:-2回答:1

我有以下代码:

Code

如何发送PDF文档“doc”而不保存它(没有文件名)?要创建一个附件对象,我需要一个文件名(路径),但我没有。

c# email attachment
1个回答
1
投票

只需选择文件的名称即可

var stream = new MemoryStream();
                doc.WriteToStream(stream);
                stream.Position = 0;

                var contentType = new ContentType(MediaTypeNames.Application.Pdf)
                {
                    Name ="withoutfilename.pdf";
                };
                var attachment = new Attachment(stream, contentType);
mailMsg.Attachments.Add(attachment);
© www.soinside.com 2019 - 2024. All rights reserved.