整合所有格式的Aspose.Total永久授权正在火热促销中,联系客服立马1分钟了解全部咨询!

使用C#将电子邮件转换为PDF的步骤
以下是在C#中将电子邮件转换为PDF格式的步骤。
-
使用MailMessage类加载电子邮件文件。
// Load email message using fileMailMessage mailMsg = MailMessage.Load("message.msg");
-
将电子邮件保存为默认MHTML格式的MemoryStream对象。
// Create memory streamMemoryStream ms = new MemoryStream();// Save email message into memory streamMailMessage.Save(ms, Aspose.Email.SaveOptions.DefaultMhtml);
-
创建Aspose.Words.LoadOptions类的实例,并将加载格式设置为MHTML。
// Create and set load optionsvar loadOptions = new Aspose.Words.LoadOptions();loadOptions.LoadFormat = LoadFormat.Mhtml;
-
实例化Aspose.Words.Document类,并将MemoryStream和LoadOptions对象作为参数传递给其构造函数。
// Create an instance of Document and load the MTHML from MemoryStreamvar document = new Aspose.Words.Document(ms, loadOptions);
-
创建一个Aspose.Words.Saving.PdfSaveOptions类的实例。
// create an instance of PDFSaveOptions classvar pdfSaveOptions = new Aspose.Words.Saving.PdfSaveOptions();
-
使用Document.Save(“ email-to-pdf.pdf”,PdfSaveOptions)方法将电子邮件转换为PDF 。
// Save email as PDFdocument.Save("email-to-pdf.pdf", pdfSaveOptions);
使用C#将电子邮件转换为PDF完整代码
// Load email messageMailMessage mailMsg = MailMessage.Load("message.msg");MemoryStream ms = new MemoryStream();mailMsg.Save(ms, Aspose.Email.SaveOptions.DefaultMhtml);// create an instance of LoadOptions and set the LoadFormat to Mhtmlvar loadOptions = new Aspose.Words.LoadOptions();loadOptions.LoadFormat = LoadFormat.Mhtml;// create an instance of Document and load the MTHML from MemoryStreamvar document = new Aspose.Words.Document(ms, loadOptions);// create an instance of HtmlSaveOptionsvar saveOptions = new Aspose.Words.Saving.PdfSaveOptions();document.Save("email-to-pdf.pdf", saveOptions);
还想要更多吗可以点击阅读【2020 · Aspose最新资源整合】,查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!