【问题标题】:node-sparkpost not including attachment in emailnode-sparkpost 不包括电子邮件中的附件
【发布时间】:2019-02-08 12:43:12
【问题描述】:

我正在尝试发送带有node-sparkpost 附件的电子邮件(在后台使用transmissions API)。

为什么下面的代码会发送邮件,但没有附件?

"use strict";
let Sparkpost = require("sparkpost");
let apiKey = "xxx";
let fromAddress = "dan@example.com";
let toAddress = "dare@example.com";

let spClient = new Sparkpost(apiKey);

spClient.transmissions
  .send({
    options: {},
    content: {
      from: fromAddress,
      subject: "The subject",
      html: "See attached file.",
      text: "See attached file."
    },
    recipients: [{ address: toAddress }],
    attachments: [
      {
        name: "attachment.json",
        type: "application/json",
        data: Buffer.from("{}").toString("base64")
      }
    ]
  })
  .then(data => {
    console.log("email mail sent");
    console.log(data);
  })
  .catch(err => {
    console.log("email NOT sent");
    console.log(err);
  });

【问题讨论】:

    标签: javascript email sparkpost


    【解决方案1】:

    一个经典的自我橡胶闪避时刻。

    attachments 属性必须是 content 的子属性:

        content: {
          from: fromAddress,
          subject: "The subject",
          html: "See attached file.",
          text: "See attached file.",
          attachments: [
            {
              name: "attachment.json",
              type: "application/json",
              data: Buffer.from("{}").toString("base64")
            }
          ]
        },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-22
      • 1970-01-01
      相关资源
      最近更新 更多