Convert each email attachment to different format
Leave feedback
GroupDocs.Conversion provides a flexible API to control the conversion of documents that contain other documents.
The following code snippet shows how to convert each attachment to a different format based on attachment type:
importcom.groupdocs.conversion.Converter;importcom.groupdocs.conversion.options.load.EmailLoadOptions;importcom.groupdocs.conversion.options.convert.PdfConvertOptions;importjava.io.IOException;importjava.io.FileOutputStream;importjava.nio.file.Files;importjava.nio.file.Paths;importjava.util.ArrayList;importjava.util.List;...EmailLoadOptionsemailLoadOptions=newEmailLoadOptions();emailLoadOptions.setConvertOwned(true);emailLoadOptions.setConvertOwner(true);emailLoadOptions.setDepth(2);Converterconverter=newConverter("sample_with_attachments.eml",emailLoadOptions);PdfConvertOptionsoptions=newPdfConvertOptions();options.setPassword("12345");options.setDpi(300);finalList<FileOutputStream>fileOutputStreams=newArrayList<>();try{converter.convert(newSaveDocumentStreamForFileType(){@OverridepublicStreaminvoke(FileTypet){try{FileOutputStreamfileOutputStream=newFileOutputStream("converted-"+fileOutputStreams.size()+".pdf");fileOutputStreams.add(fileOutputStream);returnnewGroupDocsOutputStream(fileOutputStream);}catch(IOExceptione){thrownewRuntimeException(e);}}},options);}finally{try{for(OutputStreamoutputStream:fileOutputStreams){outputStream.close();}}catch(IOExceptione){//throw an exception
}}
Warning
This functionality is introduced in v21.7
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.