首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >node-sparkpost电子邮件中不包含附件

node-sparkpost电子邮件中不包含附件
EN

Stack Overflow用户
提问于 2019-02-08 20:43:12
回答 1查看 190关注 0票数 2

我正在尝试发送一封带有附件的电子邮件,其中包含node-sparkpost (它在引擎盖下使用transmissions API )。

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

代码语言:javascript
复制
"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);
  });
EN

回答 1

Stack Overflow用户

发布于 2019-02-08 20:48:47

一个经典的自我橡皮躲避时刻。

attachments属性必须是content的子级

代码语言:javascript
复制
    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")
        }
      ]
    },
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54592748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档