'Save Outlook mailitem body as PDF

I'm working with Outlook and C# and my school exercise is to convert the body of an email in pdf without using extra software. In my case I would like to keep the email text format so to solve my problem I've considered to convert the email body in a RTF file, then open this RTF file with the Word application by C# and save it as PDF.

I would like to know how to obtain a RTF file from an MailItem. I've found on the web that it is possible to convert the MailItem body in RTF format using the BodyFormat property but i don't get how to create then a RTF.



Solution 1:[1]

The answer provided by @JoshH is good. In fact it helped me, but the only thing is that it doesn't include the embedded files present in the email body like images. If you want to do that, set the body format to HTML instead of 'FormatRichText':

MailItem.BodyFormat = OlBodyFormat.olFormatHTML;
MailItem.SaveAs("FilePath", OlSaveAsType.olRTF)

That being said, the code I provided doesn't include the attachments made to the email itself, that is, not in the body.

I hope this helps someone.

Solution 2:[2]

You can do without saving file as rtf format.

            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);

use using Word = Microsoft.Office.Interop.Word; in header

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SystemFailure
Solution 2 Shyam sundar shah