小编Par*_*ity的帖子

如何在 mailgun 电子邮件模板(Node js)中分配变量?

我制作了一个谷歌云函数,在其中我发送了一封电子邮件,其中包含我从另一个地方收到的一些变量。我正在使用mailgun.js并且我正在尝试使用我已经在 mailgun 中创建的模板发送电子邮件。问题是我找不到替换模板中占位符变量的方法。

这是代码:

mg.messages.create('domain', {
    from: 'email',
    to: [email],
    subject: 'subject',
    template: 'template',
    // How to replace the template variables???
  })
  .then(res => console.log('Resolved >>>>> ', res))
  .catch(err => console.log('MAILGUN ERROR >>>> ', err))
Run Code Online (Sandbox Code Playgroud)

mailgun文档这样说:

var data = {
  from: 'Excited User <me@samples.mailgun.org>',
  to: 'alice@example.com',
  subject: 'Hello',
  template: 'template.test',
  h:X-Mailgun-Variables: '{"title": "API Documentation", "body": "Sending messages with templates"}' // Notice this
};
Run Code Online (Sandbox Code Playgroud)

据我所知,不能将 " h:X-Mailgun-Variables"写为任何对象中的键。

有人知道我需要把它放在哪里或如何放吗?

我认为它应该作为标题发送,但mailgun/mailgun-jshighcaffeinated/mailgun-js 都没有指定如何传递标题。

javascript node.js mailgun

3
推荐指数
1
解决办法
1226
查看次数

标签 统计

javascript ×1

mailgun ×1

node.js ×1