我有一封原始电子邮件(在 playground 和工作中测试过),我想用 Google 的 Gmail API 发送它来自 Google Apps 脚本。
我找不到请求的正确语法:
var RequestUrl = "https://www.googleapis.com/gmail/v1/users/emailAccount/messages/send";
var RequestArguments = {
muteHttpExceptions:true,
headers: {Authorization: 'Bearer ' + token
'GData-Version': '3.0',
'Content-Type': "message/rfc822",
},
payload: {"raw":raw},
method:"post"
};
var result = UrlFetchApp.fetch(RequestUrl,RequestArguments);
我的语法有什么问题?
最佳答案
在 Google Apps 脚本中,您可以使用 Advanced Gmail Service无需直接对 Web API 大惊小怪。请记住,服务必须是 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;
}
关于google-apps-script - 在 Google Apps 脚本中使用 GMail API 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35062672/