I am using the following code snippet to convert an MSG file to PDF.
This works for regular Outlook emails but not for encrypted.
Is there anything I can do to perform conversion of the encrypted email messages?
Outlook Encryption Option.png (11.6 KB)
Result PDF Content.png (34.1 KB)
public class EmailToPdfConverter : IDocumentConverter
{
private readonly byte[] sourceFileBytes;
public EmailToPdfConverter(byte[] sourceFileBytes)
{
this.sourceFileBytes = sourceFileBytes;
AsposeLicenseInitializer.Initialize();
}
public byte[] Convert()
{
var sourceStream = new MemoryStream(sourceFileBytes);
var mailMessage = MailMessage.Load(sourceStream);
var mailStream = new MemoryStream();
mailMessage.Save(mailStream, MailMessageSaveType.MHtmlFromat);
var loadOptions = new LoadOptions { LoadFormat = LoadFormat.Mhtml };
var wordDocument = new Document(mailStream, loadOptions);
var targetStream = new MemoryStream();
wordDocument.Save(targetStream, SaveFormat.Pdf);
return targetStream.ToArray();
}
}