代码之家  ›  专栏  ›  技术社区  ›  Charlie Fish

节点Mailgun未附加文件

  •  0
  • Charlie Fish  · 技术社区  · 8 年前

    // 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 回复  |  直到 8 年前
        1
  •  2
  •   Ding    8 年前

    attachment 而不是 attachments .

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

    附件 .