I found and I am using EmailLoadOptions.ConvertOwned to use to Convert Emails Attachments to PDF, however the 3rd and 4th Attachments do not show. (and when I turn on show all errors it complains twice about “Unknown file format” (they are just normal.DOCX files that I can open locally like the first two). When I turn off break on all errors or just step through it completes with 3 pages, one for the email and one each for the first two attachments.
var fileStream = new MemoryStream(file);
var loadOptions = new EmailLoadOptions { ConvertOwned = true, Format = extension switch { "eml" => EmailFileType.Eml, "msg" => EmailFileType.Msg, _ => null } };
using (Converter converter = new[] { "eml", "msg" }.Contains(extension) ? new Converter(() => fileStream, () => loadOptions ) : new Converter(() => fileStream))
{
var pdfstreams = new List<MemoryStream>();
var pageStream = new GroupDocs.Conversion.Contracts.SaveDocumentStream(() => { pdfstreams.Add(new MemoryStream()); return pdfstreams.Last(); });
converter.Convert(pageStream, new PdfConvertOptions { });
if (pdfstreams.Count() == 1)
return pdfstreams.First().ToArray();
else
{
using (Merger merger = new Merger(new MemoryStream(pdfstreams.First().ToArray()), new PdfLoadOptions()))
{
for (var i = 1; i < pdfstreams.Count; i++)
merger.Join(new MemoryStream(pdfstreams[i].ToArray()));
var memoryStream = new MemoryStream();
merger.Save(memoryStream);
return memoryStream.ToArray();
}
}
}