相关疑难解决方法(0)

用于在Node.js中发送邮件的Gmail API

免责声明:

  • 我已经关注了Google自己的Node.js快速入门指南,并成功连接并使用了该 gmail.users.labels.list()功能.
  • 我在这里检查了问题/答案,就像这个(不是使用我询问的Node.js API),或者这个(类似于这个),这显然是我遇到的同样的问题,但解决方案没有工作.

我的问题:

使用Google的Node.js API时,尝试发送电子邮件时出错.错误是:

{
    "code": 403,
    "errors": [{
        "domain": "global",
        "reason": "insufficientPermissions",
        "message": "Insufficient Permission"
    }]
}
Run Code Online (Sandbox Code Playgroud)

我的设置:

fs.readFile(secretlocation, function processClientSecrets(err, content) {
    if (err) {
        console.log('Error loading client secret file: ' + err);
        return;
    }
    authorize(JSON.parse(content), sendMessage);
});

function sendMessage(auth) {
    var raw = makeBody('myrealmail@gmail.com', 'myrealmail@gmail.com', 'subject', 'message test');
    gmail.users.messages.send({
        auth: auth,
        userId: 'me',
        message: {
            raw: raw
        }
    }, function(err, response) { …
Run Code Online (Sandbox Code Playgroud)

node.js google-api-nodejs-client gmail-api

14
推荐指数
2
解决办法
1万
查看次数

Python Gmail API'不是JSON可序列化的'

我想使用Gmail API通过Python发送电子邮件.Everythings应该没问题,但我仍然得到错误"发生错误:b'Q29udGVudC1UeXBlOiB0ZXh0L3BsYWluOyBjaGFyc2V0PSJ1cy1hc2NpaSIKTUlNRS ..."这是我的代码:

import base64
import httplib2

from email.mime.text import MIMEText

from apiclient.discovery import build
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import run_flow


# Path to the client_secret.json file downloaded from the Developer Console
CLIENT_SECRET_FILE = 'client_secret.json'

# Check https://developers.google.com/gmail/api/auth/scopes for all available scopes
OAUTH_SCOPE = 'https://www.googleapis.com/auth/gmail.compose'

# Location of the credentials storage file
STORAGE = Storage('gmail.storage')

# Start the OAuth flow to retrieve credentials
flow = flow_from_clientsecrets(CLIENT_SECRET_FILE, scope=OAUTH_SCOPE)
http = httplib2.Http()

# Try to retrieve …
Run Code Online (Sandbox Code Playgroud)

python email api gmail json

6
推荐指数
2
解决办法
3319
查看次数

使用 Google API 发送邮件时出错 - “'raw' RFC822 有效负载消息字符串或通过 /upload/* URL 上传消息需要”

我正在尝试通过 Python 中的 Google API 发送消息,并尝试运行几乎直接从Google 示例页面获取的示例

def CreateMessage(sender, to, subject, message_text):
    message = MIMEText(message_text)
    message['to'] = to
    message['from'] = sender
    message['subject'] = subject
    return {'raw': base64.urlsafe_b64encode(message.as_string().replace('message','resource').encode('ascii'))}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试发送它时

    message = CreateMessage(sender, to, subject, message_text)
    message = service.users().messages().send(body=list(message),userId='me').execute()
Run Code Online (Sandbox Code Playgroud)

我收到错误消息:“'raw' RFC822 有效负载消息字符串或通过 /upload/* URL 上传消息需要”

从其他帖子看来,谷歌似乎在期待一个附件。MIMEText 有什么问题让它期待一个,如果有,我该如何解决?

python-3.x google-api-python-client gmail-api

5
推荐指数
2
解决办法
2055
查看次数