Send email using GMail API in Google Apps Script

旧街凉风 提交于 2019-12-01 21:37:58

In Google Apps Script, you can use the Advanced Gmail Service without needing to fuss with the Web API directly. Remember, the service must be enabled before use.

/**
 * Send a raw RFC 2822 formatted and base64url encoded email
 * using the Advanced Gmail service.
 *
 * From http://stackoverflow.com/a/35073785/1677912
 *
 * @param {String}  raw  RFC 2822 formatted and base64url encoded message
 *
 * @returns {String}     Message ID of the message (now in Sent Messages).
 */
function sendRawMessage( raw ) {
  var message = Gmail.newMessage();
  message.raw = raw;
  var sentMsg = Gmail.Users.Messages.send(message, 'me');
  return sentMsg.id;
}
crmpureapps

I found the solution to my question:

var RequestArguments = {
  headers: {Authorization: 'Bearer ' + token},
  method: "post",
  contentType: "application/json",
  payload: JSON.stringify(jsonMessage)
};

jsonMessage is the whole message, not only the raw part!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!