我们如何仅捕获gmail API的api响应中的电子邮件地址。该
fields参数设置为payload/headers,其回报方式更多的数据比我们需要的响应。我们需要的只是JSON响应中的value一name/value对。例如
完整的响应现在看起来像这样
{
"payload": {
"headers": [
{
"name": "Delivered-To",
"value": "xxxxxxx"
{
"name": "Received",
"value": "xxxxxxxx"
},
{
"name": "Received-SPF",
"value": "----"
},......
{
"name": "To",
"value": "xxxxxxx"
}, ...... E.T.C........E.T.C ......
/*All we want is one name/value pair to be returned e.g. */
{
"payload": {
"headers": [
{
"name": "X-Failed-Recipients",
"value": "............."
}
]
}
Run Code Online (Sandbox Code Playgroud)
一个更好的问题可能是,是否有比通过gmail API更好的方法来捕获退回/退回的邮件?
另外,是否可以请求XML响应而不是JSON。gmail API该怎么做?
谢谢 !!
我正在尝试使用 Gmail API 进行高级搜索,但我不知道如何设置查询参数。我想用 query 进行搜索is:chat,所以所有返回的消息都只是聊天消息。
在文档的示例中,他们使用了一个名为 的方法setQ("query"),但该方法仅适用于 Java。有人知道如何在 C# 中设置这个参数吗?
编辑:
在Java中,会是这样的:service.users().messages().list("me").setQ("is:chat").execute();
我正在做官方指南的客户端同步工作.
在进行部分同步时,为什么history.listapi会返回一些无法从messages.getapi 获取的id ?该messages.getAPI将返回
{
errors: [ { domain: 'global', reason: 'notFound', message: 'Not Found' } ],
code: 404,
message: 'Not Found'
}
Run Code Online (Sandbox Code Playgroud)
我在Google api explorer上得到了相同的结果.
我已经成功克隆了“原始”格式的消息,方法是使用getwithformat='raw'并重新插入它,就像这样:
params = {'userId':'me", 'id': msg_id, 'format':'raw'}
mesg = service.users().messages().get(**params).execute()
body = {'raw': mesg['raw']}
service.users().messages().insert(userId='me', body=**body).execute()
Run Code Online (Sandbox Code Playgroud)
但是我很想使用 json 格式来做同样的事情,该格式get可以通过format='full'. 像这样的东西:
params = {'userId':'me", 'id': msg_id, 'format':'full'}
mesg = service.users().messages().get(**params).execute()
body = mesg
service.users().messages().insert(userId='me', body=**body).execute()
Run Code Online (Sandbox Code Playgroud)
mesg[1]的格式见下文。做上述给我的错误:
HttpError: <HttpError 400 when requesting
https://www.googleapis.com/gmail/v1/users/me/messages?alt=json
returned "
'raw' RFC822 payload message string or uploading message via /upload/*
URL required
">
Run Code Online (Sandbox Code Playgroud)
所以问题是:
insert通过“完整”json 格式发送消息?格式是“完整”而不是“原始”,所以我应该使用上传网址吗?如何?我们是否raw以某种方式继续在or 主体中使用 json 有效负载?
我们可以将其转换为原始格式然后像以前一样吗?
我应该尝试弄清楚如何使用upload这种格式吗? …
我正在尝试在MVC 5项目中使用GMail API,但我似乎在如何使用Owin Middleware进行身份验证时遇到困难
我可以通过Google帐户登录,我也可以获得用户令牌
var googleOptions = new GoogleOAuth2AuthenticationOptions
{
ClientId = "xxx",
ClientSecret = "yyy",
SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
Provider = new GoogleOAuth2AuthenticationProvider()
{
OnAuthenticated = async ctx =>
{
ctx.Identity.AddClaim(new Claim("urn:tokens:google:accesstoken", ctx.AccessToken));
}
},
};
app.UseGoogleAuthentication(googleOptions);
Run Code Online (Sandbox Code Playgroud)
我按照预期获得了访问令牌,但此处的 Google Quicktart Tutorial 似乎提出了一种完全不同的身份验证方式
有没有办法可以使用此AccessToken来创建教程中所需的对象?或者这两个完全不同?
尝试构建符合 RFC3156 [0] 的消息,并通过 Gmail API 发送(我使用的是 python 客户端实现)。
我得到的是:在我的 Gmail 邮箱中,邮件已正确发送(我看到的正是我之前构建的邮件)·
我的接收者得到的是:一个“多部分/混合”消息,其有效载荷与我发送的消息相同。
似乎在某些时候,Gmail 更改了我的 Content-Type ......这是真的吗?
作为解决方法,我正在使用 SMTP 连接(它的行为与我预期的一样,正确发送消息),但将来我希望避免这一步,转而使用纯 Gmail API 应用程序。
你能确认这个问题吗?
[0] - 这是一个测试示例:
发送消息:
message_as_str = '''Content-Type: multipart/signed; protocol="application/pgp-signature";\n micalg="pgp-sha512"; boundary="===============0594182808971957567=="\nMIME-Version: 1.0\nDate: Wed, 12 Nov 2014 12:18:02 +0100\nSubject: A test email\nFrom: Leo Iannacone <l3on@ubuntu.com>\nTo: Andrea Colangelo <warp10@ubuntu.com>\n\n--===============0594182808971957567==\nContent-Type: text/plain; charset="utf-8"\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nHello,\r\n\r\nthis is a signed email (RFC 3156).\r\n\r\nBest,\r\nL.\r\n\r\n-- =\r\n\r\nUbuntu Member - http://launchpad.net/~l3on\r\nHome Page - http://leoiannacone.com\r\nGPG Key Id - 0xD282FC25\r\n\n--===============0594182808971957567==\nContent-Type: application/pgp-signature; name="signature.asc"\nContent-Description: GooPG digital signature\n\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG …Run Code Online (Sandbox Code Playgroud) 根据这个SO 线程,我应该能够直接转到使用 Gmail REST API 创建的 Gmail 草稿邮件,使用格式如下的超链接:
https://mail.google.com/mail/#drafts?compose={ThreadId}
Run Code Online (Sandbox Code Playgroud)
但是,它不起作用。我在响应 Gmail API 调用时获得的线程 ID 不会打开创建的草稿邮件。真正奇怪的是,当我从 Gmail(我使用 API 创建的)打开草稿时,线程 ID 确实在 URL 中匹配了几秒钟,然后发生了变化。
如何使用 message.threadId 直接打开草稿消息?我也希望它是一条弹出消息,并且应该可以根据此线程进行,但让草稿完全显示是我的首要任务。

我试图让我refresh_token生成一个新的access_token. 我正在使用请求模块发出请求,但它返回一个错误,内容类似于“找不到页面”。
var request = require('request');
module.exports = function(callback){
console.log('here');
request('https://googleapis.com/oauth2/v3/token?client_id=NotID&client_secret=Not_Secret&refresh_token=NotRefresh&grant_type=refresh_token', function (error, response, body) {
if (!error && response.statusCode == 200) {
callback(response)
}
});
}
Run Code Online (Sandbox Code Playgroud) 我正在通过 Python 中的 Gmail API 发送电子邮件,按照https://developers.google.com/gmail/api/v1/reference/users/messages/send#examples
我有一个域别名和收件箱设置,其中包含所有地址,因此发送到 nothing@sub.example.com 和anything@alias.example.com 的电子邮件最终都会出现在 tech@sub.example.com 的收件箱中。
tech@sub.example.com 和 tech@alias.example.com 在 Gmail 设置中都设置为“我拥有的帐户”,并且我在添加第二个帐户时无需验证其所有权(大概是因为它的域是别名)。
使用我正在处理的 API 处理收到的电子邮件,然后从它们被发送到的帐户重新发送它们,在 MIMEMessage 中设置“发件人”标头。不幸的是,它们总是从拥有邮箱的电子邮件地址收到。
其他问题(例如 [1]、[2])表明这应该“正常工作”,至少通过 SMTP,我也尝试过。我认为这一定是使用域别名的怪癖。
我需要与我的组织一起发送批量电子邮件。我是Java Mail API,并使用以下配置发送邮件。
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Run Code Online (Sandbox Code Playgroud)
邮件1从:abc@org.com到:emp1@org.com
邮件2从:abc@org.com到:emp2@org.com
...
邮件被循环触发。
问题:前80封电子邮件已成功发送。从第81封邮件中,我失败了,并出现以下错误,出现了10-15封邮件,后来又成功发送了几封邮件。
在743封电子邮件中,有400封失败和343封邮件是成功的。
INFO | jvm 1 | 2017/08/18 07:25:54 | com.sun.mail.smtp.SMTPSendFailedException: 421 4.7.0 Try again later, closing connection. (MAIL) xsdsfasdsa.96 - gsmtp
INFO | jvm 1 | 2017/08/18 07:25:54 |
INFO | jvm 1 | 2017/08/18 07:25:54 | at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108)
INFO | jvm 1 | 2017/08/18 07:25:54 | at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1609)
INFO | jvm 1 | 2017/08/18 07:25:54 | at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1117)
Run Code Online (Sandbox Code Playgroud)