【问题标题】:Meteor: How to use your own mailer template?Meteor:如何使用自己的邮件模板?
【发布时间】:2015-06-30 22:58:33
【问题描述】:

大家好,我有一个方法如下:

Meteor.methods({
  sendEmail: function (to, from, name, text) {

    if (Meteor.isServer) {
        return Meteor.Mandrill.send({
            to: to,
            from: from,
            name: name,
            text: text
        });
    }
  }
});

这个方法在我的contact.js中调用(html视图是contact.html):

if (Meteor.isClient) {
  // This code only runs on the client
  Template.Contact.events({
    "click .btn": function(event) {
      var from  = document.getElementById('from').value; 
      var name  = document.getElementById('name').value;
      var text  = document.getElementById('message').value;

  Meteor.call('sendEmail', 'lolotutu@gmail.com', from, name, text);

    }
  });

  Template.Contact.helpers({
    test: "Working"
  });

一切正常,但是我无法控制用于发送邮件的模板。我在这里使用 Mandrill,我想知道如何告诉我的 sendEmail 方法来提供要发送给人们的自定义模板。也许与Session.setSession.get 相关,但我无法实现它。谢谢。

【问题讨论】:

  • Saimeunt 举了一个很好的例子on this SO 看看
  • 非常感谢!我现在明白了!

标签: templates meteor customization mailer


【解决方案1】:

对于名为 yourcustomtemplate.html 的已定义模板,您可以使用以下内容:

Meteor.methods({
  sendEmail: function (to, from, name, text) {

    if (Meteor.isServer) {
        return Meteor.Mandrill.send({
            to: to,
            from: from,
            name: name,
            text: text,
            html: function(user,url){return Spacebars.toHTML({user: user.name, url: url}, Assets.getText('yourcustomtemplate.html'))}
        });
    }
  }
});

电子邮件将被格式化为以 html 格式发送,文本作为无法查看 html 的查看器的备份。

【讨论】:

    猜你喜欢
    • 2016-03-01
    • 2015-02-06
    • 1970-01-01
    • 2022-10-20
    • 1970-01-01
    • 2012-03-07
    • 2014-03-05
    • 1970-01-01
    • 2013-07-24
    相关资源
    最近更新 更多