在 Google Apps 脚本中使用 GMail API 发送电子邮件 [英] Send email using GMail API in Google Apps Script

查看:24
本文介绍了在 Google Apps 脚本中使用 GMail API 发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一封原始电子邮件(已在操场上测试并正常工作),我想使用 Google 的 Gmail 发送它API 来自 Google Apps 脚本.

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 request:

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

我的语法有什么问题?

推荐答案

我找到了我的问题的解决方案:

I found the solution to my question:

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

jsonMessage 是整个消息,而不仅仅是原始部分!

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

这篇关于在 Google Apps 脚本中使用 GMail API 发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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