Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates 流星:如何使用自己的邮件模板?_Templates_Meteor_Customization_Mailer - Fatal编程技术网

Templates 流星:如何使用自己的邮件模板?

Templates 流星:如何使用自己的邮件模板?,templates,meteor,customization,mailer,Templates,Meteor,Customization,Mailer,大家好,我有如下方法: Meteor.methods({ sendEmail: function (to, from, name, text) { if (Meteor.isServer) { return Meteor.Mandrill.send({ to: to, from: from, name: name, text: text }); }

大家好,我有如下方法:

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

    if (Meteor.isServer) {
        return Meteor.Mandrill.send({
            to: to,
            from: from,
            name: name,
            text: text
        });
    }
  }
});
此方法在my contact.js中调用(html视图为contact.html):


一切正常,但我无法控制用于发送邮件的模板。我在这里使用的是Mandrill,我想知道如何告诉我的
sendmail
方法来为发送给人们的自定义模板提供服务。可能是
Session.set
Session.get
的问题,但我在实现它时遇到了困难。谢谢。

对于名为yourcustomplate.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的查看器的备份

Saimeunt给出了一个很好的例子,看看吧,非常感谢!我现在明白了!
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'))}
        });
    }
  }
});