Google apps script 发送前未将内容添加到SendGrid模板电子邮件
我正在创建一个脚本,通过谷歌表单中的一个按钮访问,当点击时,它会发送电子邮件。我想使用SendGrid发送邮件,而不是谷歌的Google apps script 发送前未将内容添加到SendGrid模板电子邮件,google-apps-script,sendgrid,Google Apps Script,Sendgrid,我正在创建一个脚本,通过谷歌表单中的一个按钮访问,当点击时,它会发送电子邮件。我想使用SendGrid发送邮件,而不是谷歌的MailApp或Gmail。关于如何将SendGrid与Google应用程序脚本一起使用,没有太多文档 我需要使用SendGrid模板,但当我将其作为参数传递时,发送的消息只包含模板的标题,而不包含内容。为什么会发生这种情况,我如何解决 Sendgrid API需要MIME类型(如“text/plain”或“text/html”)的“content”属性的“type” 尝
MailApp
或Gmail
。关于如何将SendGrid与Google应用程序脚本一起使用,没有太多文档
我需要使用SendGrid模板,但当我将其作为参数传递时,发送的消息只包含模板的标题,而不包含内容。为什么会发生这种情况,我如何解决
Sendgrid API需要MIME类型(如“text/plain”或“text/html”)的“content”属性的“type”
尝试将
“类型”:“文本”
更改为“类型”:“文本/普通”
非常感谢您!将“text”替换为“text/html”,效果非常好!干杯很高兴听到它起作用了!单击答案左侧的复选标记,将其标记为“已接受”,并确认找到了解决方案。
var SENDGRID_KEY ='My_key';
var headers = {
"Authorization" : "Bearer "+ SENDGRID_KEY,
"Content-Type": "application/json"
};
var body = {
"personalizations": [
{ "to": [
{ "email": "name@domain"
}
],
"subject": "Hello, World!",
}
],
"from": {
"email": "name@domain"
},
"content": [
{ "type": "text",
"value": "Hello, World!"
}
],
"template_id": "My_template_id"
};
var options = {
'method': 'post',
'headers': headers,
'payload': JSON.stringify(body)
}
var response = UrlFetchApp.fetch("https://api.sendgrid.com/v3/mail/send", options);
Logger.log(response);