使用meteor触发sendgrid模板电子邮件
我正在使用sendgrid发送电子邮件。我想将模板作为电子邮件发送给用户。下面的代码只是发送简单的基于文本的电子邮件,而不是定义标题部分和使用模板id使用meteor触发sendgrid模板电子邮件,meteor,sendgrid,sendgrid-templates,Meteor,Sendgrid,Sendgrid Templates,我正在使用sendgrid发送电子邮件。我想将模板作为电子邮件发送给用户。下面的代码只是发送简单的基于文本的电子邮件,而不是定义标题部分和使用模板id if (Meteor.isServer) { Email.send({ from: "from@mailinator.com", to: "abc@mail.com", subject: "Subject", text: "Here is some text",
if (Meteor.isServer) {
Email.send({
from: "from@mailinator.com",
to: "abc@mail.com",
subject: "Subject",
text: "Here is some text",
headers: {"X-SMTPAPI": {
"filters" : {
"template" : {
"settings" : {
"enable" : 1,
"Content-Type" : "text/html",
"template_id": "3fca3640-b47a-4f65-8693-1ba705b9e70e"
}
}
}
}
}
});
}
非常感谢你的帮助
要发送SendGrid事务模板,最好使用不同的选项 1) 通过SendGrid SMPT API 在这种情况下,我们可以使用Meteor电子邮件包(正如您尝试的那样) 要添加meteor电子邮件包,我们需要键入以下内容: 在这种情况下,根据:
text
属性被替换为文本模板的,而html
被替换为html模板的。如果存在text
属性,但不存在html
,则生成的电子邮件将只包含模板的文本版本,而不包含html版本
因此,在代码中还需要提供http
属性,仅此而已
这可能是您的服务器代码:
2) 通过SendGrid Web API v3
您可以使用meteor http
包来使用SendGrid Web API v3()。在这种情况下,我们可以使用Meteor http包
要在shell中添加Meteor http包类型,请执行以下操作:
然后在服务器代码中可以使用
//使用meteor http包通过SendGrid Web API v3发送
var端点、选项、结果;
端点https://api.sendgrid.com/v3/mail/send';
选项={
标题:{
“授权”:`Bearer${Meteor.settings.sendgrid.api_key}`,
“内容类型”:“应用程序/json”
},
数据:{
个性化:[
{
致:[
{
电子邮件:userEmail
}
],
主题:“模板主题”
}
],
发件人:{
电子邮件:Meteor.settings.sendgrid.sender\u电子邮件
},
内容:[
{
键入:“text/html”,
价值:“你的身体在这里的内容”
}
],
模板id:'c040acdc-f938-422a-bf67-044f85f5aa03'
}
};
结果=HTTP.post(端点,选项);
从sendgrid文档中可以看出,您所做的一切都是正确的。流星那边也是如此。邮件中是否有标题?您是否尝试过将X-SMTPAPI
标题字符串化?您是否设法解决了此问题?
meteor add email
// Send via the SendGrid SMTP API, using meteor email package
Email.send({
from: Meteor.settings.sendgrid.sender_email,
to: userEmail,
subject: "your template subject here",
text: "template plain text here",
html: "template body content here",
headers: {
'X-SMTPAPI': {
"filters": {
"templates": {
"settings": {
"enable": 1,
"template_id": 'c040acdc-f938-422a-bf67-044f85f5aa03'
}
}
}
}
}
});
meteor add http