将 Outlook 邮件正文另存为 PDF

ato*_*Bee 2 c# outlook rtf

我正在使用 Outlook 和 C#,我的学校练习是在不使用额外软件的情况下将电子邮件正文转换为 pdf。就我而言,我想保留电子邮件文本格式,以便解决我的问题,我考虑将电子邮件正文转换为 RTF 文件,然后使用 C# 使用 Word 应用程序打开此 RTF 文件并将其另存为 PDF。

我想知道如何从 MailItem 获取 RTF 文件。我在网上发现可以使用 BodyFormat 属性将 MailItem 正文转换为 RTF 格式,但我不知道如何创建 RTF。

Shy*_*hah 5

您可以不将文件另存为 rtf 格式。

            Outlook.MailItem mi = selection[1] as Outlook.MailItem;               
            mi.BodyFormat = Outlook.OlBodyFormat.olFormatRichText;
            string fullPath = Path.Combine("SaveLocation", mi.Subject + ".pdf");
            //mi.SaveAs(fullPath, Outlook.OlSaveAsType.olRTF);                
            Word.Document doc = mi.GetInspector.WordEditor;
            doc.SaveAs2(fullPath, FileFormat: Word.WdSaveFormat.wdFormatPDF);
Run Code Online (Sandbox Code Playgroud)

使用 using Word = Microsoft.Office.Interop.Word; 在标题中