首页 文章

节点Mailgun不附加文件

提问于
浏览
0

我有以下代码,我正在尝试使用Nodegun在Node中发送电子邮件 . 代码工作正常,并发送电子邮件但不附加任何文件 .

// pdfA and pdfB are both buffers defined earlier
let attachmentA = new mailgun.Attachment({data: pdfA, filename: `pdfA.pdf`, contentType: "application/pdf", knownLength: pdfA.length});
let attachmentB = new mailgun.Attachment({data: pdfB, filename: `pdfB.pdf`, contentType: "application/pdf", knownLength: pdfB.length});
let attachments = [attachmentA, attachmentB];

var data = {
    from: "test@test.com",
    to: "emailhidden@test.com",
    subject: `My Test Email`,
    text: 'Hello',
    attachments
};

mailgun.messages().send(data, function(error, body) {
    console.log(body);
    console.log(error);
});

在NPM readme中,它提到了以下内容 .

如果附件对象不满足这些有效条件,则忽略它 . 可以通过在附件参数中传递数组来发送多个附件 . 数组元素可以是任何一种有效类型,并且每个元素都将被适当地处理 .

对于出了什么问题,这是我能找到的东西 . 但看起来我的代码满足所有条件 .

有没有办法调试这个?它目前只是默默地失败 . 它发送电子邮件,我收到它,但电子邮件中没有附件 .

1 回答

  • 1

    我不是100%肯定,但我认为你需要使用 attachment 而不是 attachments .

    例如:

    var data = {
        from: "test@test.com",
        to: "emailhidden@test.com",
        subject: `My Test Email`,
        text: 'Hello',
        attachment: attachments
    };
    

    否则, attachment 中未指定mailgun 't seeing any attachments because they' .

相关问题