Convert each email attachment to different format

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:

const fs = require('fs').promises;

const emailLoadOptions = new groupdocs.conversion.EmailLoadOptions();
emailLoadOptions.setConvertOwned(true);
emailLoadOptions.setConvertOwner(true);
emailLoadOptions.setDepth(2);

const converter = new groupdocs.conversion.Converter("sample_with_attachments.eml", emailLoadOptions);

const convertOptions = new groupdocs.conversion.PdfConvertOptions();

convertOptions.setPassword("12345");
convertOptions.setDpi(300);

const fileOutputStreams = [];
try{
    await converter.convert(async (t) => {
        try {
            const fileOutputStream = await fs.open(`converted-${fileOutputStreams.length}.pdf`, 'w');
            fileOutputStreams.push(fileOutputStream);
            return fileOutputStream;
        } catch (e) {
            throw new Error(e);
        }
    }, options);
} finally {
    try {
        for (const fileOutputStream of fileOutputStreams) {
            await fileOutputStream.close();
        }
    } catch (e) {
        // throw an exception
    }
}