如何使用 Meteor 在电子邮件中传递变量
How to pass a variable in an email with Meteor
好的,我更新了我的代码,现在看起来像这样
import { meteorhacksssr } from 'meteor/meteorhacks:ssr';
SSR.compileTemplate('InviteEmail', Assets.getText('InviteEmail.html'));
var emailData = {
name: "tom"
};
Meteor.methods({
addInvite(code) {
Invites.insert({
code : code,
sentTo: 'example@gmail.com',
accepted: false
});
var emailData = {
code: code
};
Email.send({
to: "example@gmail.com",
from: "example@email.com",
subject: "Example Email",
text: SSR.render('InviteEmail', emailData),
});
}
});
这是服务器文件夹中我的 Html 模板,名称为 InviteEmail.html
<template name="InviteEmail">
<html>
<body>
hi {{code}}
</body>
</html>
</template>
但是现在我的应用程序崩溃了 cmd 说:Error: Unknown asset: InviteEmail.html
我安装了软件包并导入了它,现在我必须修复它
感谢您的帮助 ;)
要在服务器上处理将模板转换为原始 HTML 的过程,我们需要向我们的应用程序添加一个名为 meteorhacks:ssr
的包
使用 meteor add meteorhacks:ssr
安装
用于传递任何数据以替换使用像 {{name}} 这样的车把助手
设 email.html 为
<html><body>hii {{name}}</body></html>
我们的电子邮件代码应该是这样的
SSR.compileTemplate('htmlEmail', Assets.getText('email.html'));
var emailData = {
name: "tom"
};
Email.send({
to: "to.address@email.com",
from: "from.address@email.com",
subject: "Example Email",
html: SSR.render('htmlEmail', emailData),
});
有关详细信息,请阅读此 https://themeteorchef.com/tutorials/using-the-email-package
你也可以使用 javascript 的替换功能
好的,我更新了我的代码,现在看起来像这样
import { meteorhacksssr } from 'meteor/meteorhacks:ssr';
SSR.compileTemplate('InviteEmail', Assets.getText('InviteEmail.html'));
var emailData = {
name: "tom"
};
Meteor.methods({
addInvite(code) {
Invites.insert({
code : code,
sentTo: 'example@gmail.com',
accepted: false
});
var emailData = {
code: code
};
Email.send({
to: "example@gmail.com",
from: "example@email.com",
subject: "Example Email",
text: SSR.render('InviteEmail', emailData),
});
}
});
这是服务器文件夹中我的 Html 模板,名称为 InviteEmail.html
<template name="InviteEmail">
<html>
<body>
hi {{code}}
</body>
</html>
</template>
但是现在我的应用程序崩溃了 cmd 说:Error: Unknown asset: InviteEmail.html
我安装了软件包并导入了它,现在我必须修复它
感谢您的帮助 ;)
要在服务器上处理将模板转换为原始 HTML 的过程,我们需要向我们的应用程序添加一个名为 meteorhacks:ssr
的包
使用 meteor add meteorhacks:ssr
用于传递任何数据以替换使用像 {{name}} 这样的车把助手 设 email.html 为
<html><body>hii {{name}}</body></html>
我们的电子邮件代码应该是这样的
SSR.compileTemplate('htmlEmail', Assets.getText('email.html'));
var emailData = {
name: "tom"
};
Email.send({
to: "to.address@email.com",
from: "from.address@email.com",
subject: "Example Email",
html: SSR.render('htmlEmail', emailData),
});
有关详细信息,请阅读此 https://themeteorchef.com/tutorials/using-the-email-package
你也可以使用 javascript 的替换功能