代码之家  ›  专栏  ›  技术社区  ›  iuliu.net

mailgun.js是否提供发送模板的可能性?

  •  0
  • iuliu.net  · 技术社区  · 5 年前

    所以 MailGun 提供了通过实现其 API 以下内容:

    var mailgun = require('mailgun-js')({ apiKey: api_key, domain: DOMAIN });
    
    var filepath = path.join(__dirname, 'sample.jpg');
    
    var data = {
      from: 'Excited User <me@samples.mailgun.org>',
      to: 'foo@example.com, baz@example.com, bar@example.com',
      cc: 'baz@example.com',
      bcc: 'bar@example.com',
      subject: 'Complex',
      text: 'Testing some Mailgun awesomness!',
      html: "<html>HTML version of the body</html>",
      attachment: filepath
    };
    
    mailgun.messages().send(data, function (error, body) {
      console.log(body);
    });
    

    它们也提供了设计和创造的可能性 Email Templates 是的。有没有什么方法可以通过api发送带有自定义变量的模板电子邮件?类似于:

    var data = {
      from: 'Excited User <me@samples.mailgun.org>',
      to: 'foo@example.com, baz@example.com, bar@example.com',
    
      template: "withdraw_request_approved", //Instead of 'html'
      vars: { firstName: 'John', lastName: 'Doe' }
    };
    
    mailgun.messages().send(data, function (error, body) {
      console.log(body);
    });
    

    如果没有,你能推荐其他提供这种功能的邮件服务吗?(我跳过了 Mandrill 因为它现在显然已经关闭了,没有明确的估计它什么时候可以再次使用)

    0 回复  |  直到 5 年前
        1
  •  7
  •   adnan kamili    5 年前

    是的,您可以,您的案例格式如下:

    var data = {
      from: 'Excited User <me@samples.mailgun.org>',
      to: 'foo@example.com, baz@example.com, bar@example.com',
    
      template: "withdraw_request_approved", //Instead of 'html'
      'v:firstName': 'John',
      'v:lastName': 'Doe'
    };