【问题标题】:AWS-SES sending mail with attachment [application/pdf] Nodejs [duplicate]AWS-SES 发送带有附件的邮件 [应用程序/pdf] Nodejs [重复]
【发布时间】:2023-04-07 06:10:01
【问题描述】:

我有多个 .pdf 附件,我想将附件作为对象数组传递给 SendEmail 函数,如下所示。我通读了 AWS 文档,没有关于附件的信息。


   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
    });

【问题讨论】:

  • 我从node-ses docs 了解到的是它不支持您想要的附件。您只能构建原始电子邮件并在其中放置附件。查看nodemailer,它具有开箱即用的附件支持。

标签: node.js pdf email-attachments amazon-ses


【解决方案1】:

AWS SES 提供了配置和发送电子邮件的有效方式。请参考以下帖子。它对我有用。 How can send PDF attachment in `Node aws-sdk` sendRawEmail function?

【讨论】:

    【解决方案2】:

    使用方便 https://nodemailer.com/transports

    SES 在我看到那个网址后花了我 3 个小时

    【讨论】:

    【解决方案3】:

    我通过使用邮件编辑器找到了解决方案,并且效果很好。

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

    【讨论】:

    猜你喜欢
    • 2020-07-03
    • 2017-09-28
    • 2014-12-31
    • 2019-12-07
    • 2022-11-25
    • 2014-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多