Gmail REST API json发送消息 [英] Gmail Rest API json to send message

查看:0
本文介绍了Gmail REST API json发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

向Gmail API发送json请求时遇到问题。 我可以访问独家新闻https://www.googleapis.com/auth/gmail.send,它允许我访问发送方法。

在Google文档中,他们指出,其余的需要在下面提供这些数据。 https://developers.google.com/gmail/api/reference/rest/v1/users.messages

但是我不能装满它们,要往里面放什么呢? 有没有人曾经通过REST只发送一个json来使用API?

我在堆栈上进行了研究,但没有找到有这种困难的人。和Google文档上没有任何示例。

{
  "id": string,
  "threadId": string,
  "labelIds": [
    string
  ],
  "snippet": string,
  "historyId": string,
  "internalDate": string,
  "payload": {
    object (MessagePart)
  },
  "sizeEstimate": integer,
  "raw": string
}

推荐答案

消息应编码为Base64。您可以通过将此代码粘贴到节点REPL或在线节点编译器来生成一个节点,如下所示 https://replit.com/languages/nodejs

function createMessageJson(){
    const messages = [
        'From: NAME <foo@email.com>',
        'To: Name <foobar@email.com>',
        'Content-Type: text/html; charset=utf-8',
        'MIME-Version: 1.0',
        'Subject: Re: SUBJECT',
        '',
        'BODY_TEXT',
        '',
    ];


    function encodedMessage (){
        return Buffer.from(messages.join('
'))
            .toString('base64')
            .replace(/+/g, '-')
            .replace(///g, '_')
            .replace(/=+$/, '');
    }


  return JSON.stringify({
            raw: encodedMessage()
    });
}

console.log(createMessageJson())

这篇关于Gmail REST API json发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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