Restrict attaching files in email if file size is above 10MB (individual attachment must not exceed 10MB)

Assume variable pdfAttachment contain array of loaded attached file.

if (pdfAttachment.length > 0) {
    let isAttachedSizeExceed = pdfAttachment.some(object => parseFloat(object.size) > 10485760);
    if (isAttachedSizeExceed === true) {
        pdfAttachment = [];
    }
}
email.send({
    author: '<author>',
    recipients: '<recipients>',
    cc: '<ccMailId>',
    subject: '<mailSubject>',
    body: '<emailContent>',
    attachments: pdfAttachment
});

Leave a comment

Your email address will not be published. Required fields are marked *