我需要使用gmail api获取收件箱中的所有邮件.但我只看到一种方法.
获取消息列表(id,threadID)
GET https://www.googleapis.com/gmail/v1/users/somebody%40gmail.com/messages?labelIds=INBOX&key={YOUR_API_KEY}
Run Code Online (Sandbox Code Playgroud)使用id`s循环获取所有消息
While
GET https://www.googleapis.com/gmail/v1/users/somebody%40gmail.com/messages/147199d21bbaf5a5?key={YOUR_API_KEY}
End of While
Run Code Online (Sandbox Code Playgroud)但是这种方式需要100500请求.有人知道如何获得一个请求所有消息(或只是有效载荷字段)?
我想用Python发送Gmail-API的电子邮件,但我经常收到以下错误:
<HttpError 400 when requesting https://www.googleapis.com/gmail/v1/users/me/messages/send?alt=json returned "Invalid value for .....">
我试图改变一切,并得出结论,当我在电子邮件中包含一个双开关闭角括号('<<'和'>>')(参见示例)时会发生错误.我尝试了将所有内容解析为其他内容,但我认为问题在于我使用'raw'这一事实......但'raw'是Google展示的唯一方式.
还有另一种方法可以通过gmail-api发送电子邮件吗?或者,换句话说,我能做些什么才能在文本中发送带尖括号的电子邮件?
谢谢!
我目前的代码如下(来自Google的示例代码):
import base64
from email.mime.audio import MIMEAudio
from email.mime.base import MIMEBase
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import mimetypes
import os
from apiclient import errors
(...other code...)
SendMessage(service, "me", CreateMessage("me", sender, "<<NOT OK>> " + action, "TEST!"))
(...other code...)
def SendMessage(service, user_id, message):
"""Send an email message.
Args:
service: Authorized Gmail API service instance.
user_id: User's email address. …Run Code Online (Sandbox Code Playgroud) 如果您已登录多个Gmail帐户,Google会更改网址以引用您当前使用的帐户.例如:
https://mail.google.com/mail/u/0/#inbox/138d85da096d2126我的主帐户https://mail.google.com/mail/u/1/#inbox/128cfe99d055805d中的convo与另一个帐户
中的convo相比.
请注意,一个帐户/u/0在URL中有另一个帐户u/1.
我的问题是:鉴于我已使用Gmail REST API查找特定线程的ID,我该如何可靠地链接到该线程?是否有任何编程方式向Google询问用户登录的帐户,以及每个帐户属于哪个序列(0,1,2,...)?
我试图通过代码发送电子邮件,我遇到了障碍.当Base64UrlEncode出现红色时,我正在解决这个问题.我的代码中有相同的using语句.
using System;
using System.IO;
using System.Net.Mail;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MyCompany.Sample.EmailConnector.Model;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Gmail.v1;
using Google.Apis.Gmail.v1.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
...
public static Message createGmailMessage(AE.Net.Mail.MailMessage mailMessage)
{
var messageString = new StringWriter();
mailMessage.Save(messageString);
Message gmailMessage = new Message();
gmailMessage.Raw = Base64UrlEncode(messageString.ToString());
}
Run Code Online (Sandbox Code Playgroud)
如何启用"Base64UrlEncode"?
我的机构目前从2009年初开始运行Google Apps for Education.我负责创建,删除,修改学生电子邮件帐户等.我已将所有现有的C#应用程序从GData转换为新的Admin SDK - 生活很美好.
上周,其中一个部门向大约800名学生发送了一封包含错误的电子邮件.我被问到是否可以创建一个能够删除800个学生收件箱的电子邮件的快速应用程序.
使用我的"超级管理员"域帐户,我可以使用Gmail API创建一个应用程序,以进入我的收件箱并选择符合特定条件的特定电子邮件; 示例:from:xxxx@domain.edu AND is:unread AND subject:test 我能够返回消息ID的集合,然后我可以从收件箱中删除它们 - 太棒了!
由于我能够在我的收件箱中执行此操作,因此我认为我会进行另一项测试并插入其中一个800电子邮件地址并获得相同的结果.不幸的是我收到此错误消息:
错误:Google.Apis.Requests.RequestError拒绝委托xxxxx@domain.edu [403]错误[消息[委托被拒绝xxxxx@domain.edu]位置[ - ]原因[禁止]域[全局]]
我确实阅读了有关帐户委派的内容,但这需要从我的"超级管理员"帐户发送请求,并且学生接受该请求.
可能是域名的"超级管理员"在任何收件箱中没有这些权限,除了他们自己的?我试过阅读帖子和谷歌的文档,但我似乎无法找到关于这个主题的答案.
在此桌面应用程序的开发人员控制台中启用了Gmail API.
我正在使用的服务帐户已获得授权,并且在C#应用程序中使用的是正确的范围:
Scopes = new[] {
"https://mail.google.com",
GmailService.Scope.GmailCompose,
GmailService.Scope.GmailInsert,
GmailService.Scope.GmailLabels,
GmailService.Scope.GmailModify,
GmailService.Scope.GmailReadonly,
GmailService.Scope.MailGoogleCom,
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile"},
Run Code Online (Sandbox Code Playgroud)
我的C#代码:
List<Google.Apis.Gmail.v1.Data.Message> result = new List<Google.Apis.Gmail.v1.Data.Message>();
UsersResource.MessagesResource.ListRequest request = GoogleToken.GoogleService().Users.Messages.List("xxxxx@domain.edu");
request.Q = " from:xxxx@domain.edu AND is:unread AND subject:test ";
do
{
try
{
ListMessagesResponse response = request.Execute();
result.AddRange(response.Messages);
request.PageToken = response.NextPageToken;
}
catch (Exception eX)
{
Debug.WriteLine("Error: " …Run Code Online (Sandbox Code Playgroud) 我一直在尝试通过REST查询Google GMAIL API。
我已经完成以下操作:
1.在console.developer.google.com中创建一个项目
2.为该项目创建一个API密钥
3.在控制台中启用Gmail API
4.现在,我尝试执行以下操作cURL请求:
curl -H 'Content-Type: application/json' -H 'Accept: application/json' https://www.googleapis.com/gmail/v1/users/<email_id>/messages?key=<my_API_KEY>
Run Code Online (Sandbox Code Playgroud)
但我得到以下回应
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
提前致谢
我正在使用Laravel-5.1进行开发.我有.env配置文件在开发环境上正常工作,这是Windows 8,4GB RAM.当我部署到Centos-6的远程服务器时,我开始收到此错误:
Swift_TransportException in StreamBuffer.php line 265:
Connection could not be established with host smtp.gmail.com [Permission denied #13]
in StreamBuffer.php line 265
at Swift_Transport_StreamBuffer->_establishSocketConnection() in StreamBuffer.php line 62
at Swift_Transport_StreamBuffer->initialize(array('protocol' => 'tcp', 'host' => 'smtp.gmail.com', 'port' => '587', 'timeout' => '30', 'blocking' => '1', 'tls' => true, 'type' => '1')) in AbstractSmtpTransport.php line 113
at Swift_Transport_AbstractSmtpTransport->start() in Mailer.php line 79
at Swift_Mailer->send(object(Swift_Message), array()) in Mailer.php line 395
at Mailer->sendSwiftMessage(object(Swift_Message)) in Mailer.php line 181
at Mailer->send('email.verify', array('users' => object(User), 'confirmation_code' …Run Code Online (Sandbox Code Playgroud) 我想为某些参数集创建一个gmail原生的过滤器.
基本上我经常使用google别名功能(电子邮件后面的+号).我想自动创建一个过滤器,读取"To"行,然后查找"+".如果找到a"+",它将标记"+"之后的内容.然后它将创建一个专用/本机过滤器,它将:跳过收件箱并应用"+"之后的标签.
我查看了gmail脚本,但没有找到制作本机过滤器的方法.我知道这个功能可能刚刚实现.
function getTo() {
// Log the To line of up to the first 50 emails in your Inbox
var email = Session.getActiveUser().getEmail();
Logger.log(email);
var threads = GmailApp.getInboxThreads(0, 50);
for (var i = 0; i < threads.length; i++) {
var messages = threads[i].getMessages();
for (var j = 0; j < messages.length; j++) {
Logger.log(messages[j].getTo()||email);
}
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助都会很棒.
解:
// Creates a filter to put all email from ${toAddress} into
// Gmail label ${labelName}
function createToFilter(toAddress, labelName) { …Run Code Online (Sandbox Code Playgroud) 要求是将用户的Gmail邮件同步到我们的CRM中.适当的系统基于Google Pub/Sub,用于监视用户的收件箱以进行任何更改,并将通知发送到我们的HTTPs端点.有关此内容的更多信息,请访问Gmail cloud pub/sub.
根据上述程序,我们将改变历史.然后我只对新消息感兴趣,因此根据本指南首选history.getMessagesAdded .我们现在面临的问题是没有在messagesAdded下捕获线程的第一个邮件,所有后续消息都通过我们的系统传递.
注意:对于第一封邮件,我们会从Google推送.但是当我们尝试添加消息时,它变得空洞.是否有任何特殊需要为线程的第一个邮件做或我错过了什么.
java gmail gmail-api google-cloud-pubsub google-console-developer
Gmail OAuth API一直运行良好,直到2月17日,并POST /o/oauth2/token在刷新OAuth令牌时随机返回此错误:
此消息类型不允许使用参数:redirect_uri
该错误大约发生在10次中.奇怪的是,在收到此错误后,下一个完全相同的请求成功.因此,这与错误消息所建议的"redirect_uri"无关.
"其他StackOverflow帖子中已报告"此消息类型不允许参数",但它们都是持久性错误,可以通过修复参数来解决.虽然我们得到的错误是暂时的.10%的费率对用户体验来说是昂贵的.
最近有没有人见过类似的行为?
gmail-api ×10
gmail ×3
email ×2
google-api ×2
google-oauth ×2
c# ×1
java ×1
laravel-5.1 ×1
messages ×1
python ×1
quota ×1
request ×1
rest ×1
smtp ×1