Send email using GMail API in Google Apps Script

前端 未结 2 2011
面向向阳花
面向向阳花 2021-01-21 01:47

I have a raw email (tested on playground and working) and I want to send it with Google\'s Gmail API from Google Apps Script.

I can\'t find the right syntax for the requ

2条回答
  •  孤独总比滥情好
    2021-01-21 02:12

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

提交回复
热议问题