Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS-SES sending mail with attachment [application/pdf] Nodejs [duplicate]

I have multiple .pdf attachments and I want to pass the attachments as an array of objects as shown below to the SendEmail function. I read through the AWS documents and there was no information regarding attachments.


   let attachment_data = [];
    attachment_data.push({
        filename: 'ticket.pdf',
        path:'/sample/tickets/ticket.pdf',
        content: new Buffer(fs.readFileSync('/sample/tickets/ticket.pdf')).toString('base64'),
        contentType: 'application/pdf',
    });


-----------------------------------------------------------------------



    function SendMail(options, template, cb) {
        for (var key in options) {
            template = template.replace('{{%' + key + '%}}', options[key]);
        }
        client.sendEmail({
            from: constants.EMAIL_FROM,
            to: options.email,
            subject: options.subject,
            message: template,    //html content
            attachments: (options.attachment)?options.attachment:null  //array of objects
        }, function(err, data, res) {
            if(err) cb(err, null);
            else cb(null,res)
       });
    }

------------------------------------------------------------------------
am receiving email but without attachment and I looked all over the documentation and all but all I could find is this statement below which is relevant.

 - **The total size of the message, including attachments, must be smaller
   than 10 MB.**

am using the below package [node-ses][1]

    var ses = require('node-ses'),
    client = ses.createClient({
        key: process.env.AWS_ACCESSKEY_ID,
        secret: process.env.AWS_SECRET_ACCESSKEY,
        amazon: process.env.SES_REGION
    });
like image 836
lawrence999 Avatar asked Feb 06 '18 04:02

lawrence999


1 Answers

Easy for use this https://nodemailer.com/transports

SES take me 3 hours after i seen that url

like image 147
tile Avatar answered Nov 06 '22 02:11

tile