内容在发送之前未添加到SendGrid模板电子邮件中 [英] Content not added to SendGrid template email before it is sent

查看:58
本文介绍了内容在发送之前未添加到SendGrid模板电子邮件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个脚本,该脚本可通过Google表格中的按钮访问,单击该脚本即可发送电子邮件.我想使用SendGrid而不是Google的 MailApp Gmail 发送邮件.关于如何将SendGrid与Google Apps脚本一起使用的文档并不多.

I am creating a script accessed by a button in Google Sheets that when clicked, sends emails. I want to use SendGrid to send my mails rather than Google's MailApp or Gmail. There is not a lot of documentation on how to use SendGrid with Google Apps Script.

我需要使用SendGrid模板,但是当我将其作为参数传递时,发送的消息仅包含模板的标头,而不包含内容.为什么会发生这种情况,我该如何解决?

I need to use SendGrid templates, but when I pass it as a parameter, the sent message consists only of the header of the template and not the content. Why is this happening, and how can I resolve it?

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

推荐答案

Sendgrid API需要MIME类型(例如"text/plain"或"text/html")的"content"属性的"type".

The Sendgrid API requires the "type" of the "content" property by a MIME Type, such as "text/plain" or "text/html".

尝试将"type":"text" 更改为"type":"text/plain"

这篇关于内容在发送之前未添加到SendGrid模板电子邮件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆