javascript - node-sparkpost 不包括电子邮件中的附件

标签 javascript email sparkpost

我正在尝试发送一封带有 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);
  });

最佳答案

一个经典的 self 橡皮回避时刻。

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")
        }
      ]
    },

关于javascript - node-sparkpost 不包括电子邮件中的附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54592748/

相关文章:

javascript - 基于eq()选择的点击事件

javascript - EXTJS 扩展 Ext.data.JsonStore

php - 将表单发送到用户永远不知道或看到的 php 脚本

node.js - 为什么带有 SparkPost 的电子邮件会成为垃圾邮件?

php - 如何在 Microsoft Azure 中验证 SparkPost 的发送域?

bash - curl:参数列表太长

React : why isn't my function returning multiple divs? 中的 Javascript 函数

javascript - 平滑滚动脚本阻止链接

php - 检查电子邮件是否已存在于数据库中 jquery +php

php - 使用 PHP mail() 函数的 SMTP 身份验证