test.zip (540.7 KB)
When converting an email (msg file) with an image attachment to PDF, the attachement is included in the mail body. Other attachments do not show this behavior
Sample code:
import com.aspose.email.MailMessage;
import com.aspose.email.SaveOptions;
import com.aspose.words.Document;
import com.aspose.words.LoadFormat;
import com.aspose.words.LoadOptions;
import com.aspose.words.PdfSaveOptions;
import com.aspose.words.SaveFormat;
try ( InputStream fis = new FileInputStream( source ) ) {
// convert to MHTML
MailMessage eml = MailMessage.load( fis );
ByteArrayOutputStream baos = new ByteArrayOutputStream();
eml.save( baos, SaveOptions.getDefaultMhtml() );
// convert to PDF
LoadOptions lo = new LoadOptions();
lo.setLoadFormat( LoadFormat.MHTML );
Document doc = new Document( new ByteArrayInputStream( baos.toByteArray() ), lo );
doc.save( target.getAbsolutePath(), SaveFormat.PDF );
}