Google App ScriptでSendGridを利用したメール送信方法

マニフェストファイルappsscript.jsonに以下で許可登録

"oauthScopes": ["https://www.googleapis.com/auth/script.external_request","https://www.googleapis.com/auth/spreadsheets.currentonly","https://www.googleapis.com/auth/documents"],

以下コード(テキストメール)

SEND_GRID_ENDPOINT = "https://api.sendgrid.com/v3/mail/send";
SEND_GRID_API_KEY = "あなたのAPIキー";

function sendEmailBySendGrid(to,subject,from,from_name,bcc,body_text){ 
  var body = {
    "personalizations": [
      {
        "to": [
          {
            "email": to
          }
        ],
        "bcc":[
          {
            "email": bcc
          }
        ],
        "subject": subject
      }
    ],
    "from": {
      "email": from,
      "name" : from_name
    },
    "content": [
      {
        "type": "text", // htmlメールにしたいなら"text/html"
        "value": body_text
      }
    ]
  }
  var payload = JSON.stringify(body);
  UrlFetchApp.fetch(SEND_GRID_ENDPOINT, {
    method: 'POST',
    headers: { "Content-Type": 'application/json',
             "Authorization": "Bearer "+SEND_GRID_API_KEY},
    payload: payload
  });
}