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'))}
});
}
}
});