6

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
    });
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
lawrence999
  • 77
  • 1
  • 1
  • 5
  • What I understand from `node-ses` docs is that it doesn't support attachments the way you want. You can only build a raw email and have the attachment there. Check out [nodemailer](https://www.npmjs.com/package/nodemailer) it has attachment support out of the box. – Alex Michailidis Feb 06 '18 at 08:33
  • From multiple different solutions [this](https://stackoverflow.com/a/49364968/5375291) one actually worked pretty well. – Debu Shinobi Mar 15 '22 at 10:10

3 Answers3

3

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

SES take me 3 hours after i seen that url

tile
  • 155
  • 1
  • 8
  • 2
    good example: https://medium.com/@xoor/sending-emails-with-attachments-with-aws-lambda-and-node-js-e6a78500227c – h-kippo Aug 09 '18 at 14:19
0

I found solution by using mail composer and it worked just fine.

https://disjoint.ca/til/2017/09/20/how-to-send-emails-with-attachments-using-the-node.js-api-for-amazon-ses/

lawrence999
  • 77
  • 1
  • 1
  • 5
  • 4
    that project is no longer maintained: https://github.com/nodemailer/mailcomposer – h-kippo Aug 09 '18 at 14:18
  • Suggested to read the AWS JS SDK official documentation here https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/ses-examples-sending-email.html – Yajairo87 Aug 02 '19 at 21:59
  • 5
    The above SDK link has no examples of sending an email with attachments, so don't waste your time reading through it. – Francis Jul 08 '20 at 04:01
-1

AWS SES provides efficient way of configuring and sending email. Please refer to the following post. It worked for me. How can send PDF attachment in `Node aws-sdk` sendRawEmail function?