繁体   English   中英

流星电子邮件模板

[英]Meteor Email Template

我正在尝试在服务器端发送HTML电子邮件,这是我正在关注的

  1. meteor add blaze
  2. 客户端:

var dataContext = {
    from: "wrs@mw.com",
    to: event.speakers[i].email,
    name: event.speakers[i].fname + " " + event.speakers[i].lname,
    subject: "Invitation to Event <h3>" + event.title + " !",
    message: "You must see this, it's amazing !",
    url: "http://myapp.com/content/amazingstuff"
};

Meteor.call('sendInvitationEmail', dataContext);
  1. 服务器端:

Meteor.methods({
    sendInvitationEmail: function(subject, data) {
        var html = Blaze.toHTML(Blaze.With(data, function() {
            return Template.invitation;
        }));
        Email.send({
            to: data.to,
            from: data.from,
            subject: data.subject,
            html: html
        });
    }
});
  1. 服务器模板:

<template name="invitation">
   Hello {{name}},
   {{title}}
   {{message}}
   {{url}}
</template>

我收到一个错误:

“调用方法'sendInvitationEmail'时出错:内部服务器错误[500]”

这是解决方案:

meteor add cmather:handlebars-server

安装此软件包后,您将可以访问服务器上的模板,例如:

html = Handlebars.templates.invitation(data)

官方存储库中有更多文档

优秀的meteorhacks:ssr包可以提供服务器端渲染。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM