我正在寻找在我正在使用的应用程序中使用Gmail API.但是,我不确定如何将他们的Java或Python示例更改为C#.现有样本究竟如何转变?
我在解码使用Gmail API收到的电子邮件的邮件正文时遇到严重问题.我想抓取消息内容并将内容放在div中.我正在使用base64解码器,我知道它不会解码编码不同的电子邮件,但我不知道如何检查电子邮件以决定使用哪个解码器 - 说明它们是utf-8编码的电子邮件已成功解码base64解码器,但不是utf-8解码器.
我已经研究了几天的电子邮件解码,而且我已经了解到我在这里的联盟有点不合适.我之前没有做过很多关于电子邮件编码的工作.这是我用于获取电子邮件的代码:
gapi.client.load('gmail', 'v1', function() {
var request = gapi.client.gmail.users.messages.list({
labelIds: ['INBOX']
});
request.execute(function(resp) {
document.getElementById('email-announcement').innerHTML = '<i>Hello! I am reading your <b>inbox</b> emails.</i><br><br>------<br>';
var content = document.getElementById("message-list");
if (resp.messages == null) {
content.innerHTML = "<b>Your inbox is empty.</b>";
} else {
var encodings = 0;
content.innerHTML = "";
angular.forEach(resp.messages, function(message) {
var email = gapi.client.gmail.users.messages.get({
'id': message.id
});
email.execute(function(stuff) {
if (stuff.payload == null) {
console.log("Payload null: " + message.id);
}
var header = "";
var …Run Code Online (Sandbox Code Playgroud) 我正在研究电子邮件平台(使用Objective-C语言),并希望使用GTMHTTPFetcher和GTMOAuth2Authentication框架获取一些邮件.我正在使用gmail API获取userinfo并获得适当的响应.
我想为用户的收件箱中的类别提取电子邮件; 我正在考虑使用SYSTEM级别标签,例如CATEGORY_SOCIAL用于社交,CATEGORY_PERSONAL用于个人/主要等.
对于此功能,我正在使用以下GET API:https://www.googleapis.com/gmail/v1/users/userId/messages API以及适当的参数.我正在使用google试试这个选项. https://developers.google.com/gmail/api/v1/reference/users/messages/list#try-it
问题:我能够获得所有的messageID/threadID,但无法在google开发者控制台中获取labelID.我也从Objective-C代码尝试了这个GET方法,但是没有得到labelID.
我已经附上了Objective-C代码的代码片段,你能帮帮我解决这个问题吗?
NSString *newAPIStr = @"";
newAPIStr = [NSString stringWithFormat:@"https://www.googleapis.com/gmail/v1/users/%@/messages?fields=messages(id,labelIds,threadId),nextPageToken&maxResults=%d",emailStr,maxResult];
NSURL *url = [NSURL URLWithString:newAPIStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"GET"];
GTMOAuth2Authentication *currentAuth = [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName clientID:kMyClientID clientSecret:kMyClientSecret];
GTMHTTPFetcher* myFetcher = [GTMHTTPFetcher fetcherWithRequest:request];
[myFetcher setAuthorizer:currentAuth];
[myFetcher beginFetchWithCompletionHandler:^(NSData *retrievedData, NSError *error) {
if (error != nil) {
// status code or network error
} else {
// succeeded
NSDictionary* json = [NSJSONSerialization …Run Code Online (Sandbox Code Playgroud) 在.Net中使用GMail API.使用Net.Mail.MailMessage创建消息传递.然后使用MimeKit创建MimeMessage(使用此方法发送附件+ HTML消息).将MimeMessage.ToString传递给Base64编码器.没有API错误.代码运行正常.我可以在GMail的已发送页面中看到该消息.邮件看起来很完美(发送实际返回消息ID).但是,Gmail中的此邮件会附加以下附加消息.
Bounce <nobody@gmail.com>
An error occurred. Your message was not sent.
Run Code Online (Sandbox Code Playgroud)
像往常一样,谷歌没有其他信息.如何解决这个问题?
Dim msg = New Net.Mail.MailMessage
msg.Subject = subject
msg.To.Add(New MailAddress(ToEmail))
msg.From = New MailAddress(FromEmail, SenderName)
msg.ReplyTo = New MailAddress(FromEmail, SenderName)
msg.Body = bodyText
msg.IsBodyHtml = True
If Not String.IsNullOrWhiteSpace(fileAttachment) Then
If System.IO.File.Exists(fileAttachment) Then
Dim Attachment As New Net.Mail.Attachment(fileAttachment, "application/pdf")
msg.Attachments.Add(Attachment)
End If
End If
Dim message As MimeMessage = MimeMessage.CreateFromMailMessage(msg)
Dim newMsg = New Google.Apis.Gmail.v1.Data.Message()
newMsg.Raw = Base64UrlEncode(message.ToString)
GmailService.Users.Messages.Send(newMsg, "me").Execute()
Private Function Base64UrlEncode(ByVal input As String) …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用gmail api阅读gmail邮件,并在阅读邮件后,我正在删除邮件标签,以便我不需要再次处理它.我能够成功读取邮件,但是当我尝试修改邮件时Label
(service.Users.Messages.Modify(mods, userId, messageId).Execute();)
然后我收到错误信息:
发生错误:Google.Apis.Requests.RequestError
权限不足[403]
错误[
消息[权限不足]位置[ - ]原因[insufficientPermis
sions]域[global]>
].
我无法弄明白,可能出了什么问题?提前致谢.
我正在尝试创建一个应用程序,以确定收件人是否已使用GMAIL的推送通知回复了我的电子邮件.它运行良好,但问题是,我收到通知我的Gmail上的任何更改.
这是我使用的代码
request = {
'labelIds': ['UNREAD'],
'topicName': topic,
'labelFilterAction': 'include'
}
service.users().watch(userId=user.google_id, body=request).execute()
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用'labelFilterAction':'排除'
system_labels = ['CATEGORY_UPDATES', 'UNREAD', 'DRAFT', 'CATEGORY_PROMOTIONS', 'INBOX', 'CATEGORY_SOCIAL', 'CATEGORY_PERSONAL', 'CATEGORY_FORUMS', 'TRASH', 'CHAT', 'IMPORTANT', 'SENT', 'STARRED', 'SPAM']
system_labels.remove('UNREAD')
request = {
'labelIds': system_labels,
'topicName': topic,
'labelFilterAction': 'exclude'
}
service.users().watch(userId=user.google_id, body=request).execute()
Run Code Online (Sandbox Code Playgroud)
有了这个,我根本没有收到任何通知.有什么建议吗?
我通过Gmail的API发送内联附件时遇到了一个奇怪的问题.我使用的是.NET客户端(版本1.10.0).该电子邮件是对我通过内联附件收到的邮件的回复,因此该附件是回复中引用的块的一部分.
这是我发送的原始MIME消息:
From: ...
To: ...
Date: Fri, 01 Jul 2016 11:48:29 -0700
Subject: Re: attachment test #2
Message-Id: ...
In-Reply-To:...
References: ...
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-JOa+9Bw0690XCFj1YCPc1Q=="
--=-JOa+9Bw0690XCFj1YCPc1Q==
Content-Type: text/html; charset=utf-8
Content-Id: <W4PKNTOPLYT4.32IVHE45EWK21@BILLRAVDIN9F02>
<div style="font-family: Helvetica, Arial, sans-serif;">back atcha.<div><br>On Fri, Jul 01, 2016 at 11:38 AM, ... wrote:<div>[Omitted for clarity]<img height="168" width="300" src="cid:8AF6D64A-9AAD-4E54-8998-5F08C42F537F"></span></div><br></div></div></div></div></div>
--=-JOa+9Bw0690XCFj1YCPc1Q==
Content-Type: image/jpeg; name="ha ha.jpeg"
Content-Disposition: inline; filename="ha ha.jpeg"
Content-Transfer-Encoding: base64
Content-Id: <8AF6D64A-9AAD-4E54-8998-5F08C42F537F>
[Base64 encoded attachment]
--=-JOa+9Bw0690XCFj1YCPc1Q==--
Run Code Online (Sandbox Code Playgroud)
请注意上面内联附件的mime部分的内容配置:
内容处理:内联 ; filename ="ha ha.jpeg"
以下是内联附件部分的MIME标题在出现时的样子:
Content-Type: …Run Code Online (Sandbox Code Playgroud) $firstEmail = "joe@gmail.com";
$secondEmail = "notjoe@gmail.com";
Function Set-MIMEBase64Encoded
{
Param(
[string]$subject
)
#Creates a MIME formatted email.
$text = "From: $firstEmail\r\n" + "To: $secondEmail\r\n" + "Subject: $subject\r\n\r\n" + "$subject";
$bytes = [System.Text.Encoding]::Unicode.GetBytes($text);
#Converts to Base 64.
$encodedText =[Convert]::ToBase64String($bytes);
#Makes encoding URL safe.
$urlSafe1 = $encodedText.replace('+', '-');
$urlSafe2 = $urlSafe1.replace('/', '_');
$urlSafe3 = $urlSafe2.replace('=', '*');
return $urlSafe3;
}
Function Mail-Output
{
Param(
[String]$subject
)
#Acquires access token.
$accessToken = Refresh-AccessToken;
#Sends subject for MIMEB64 encoding
$text = Set-MIMEBase64Encoded -subject $subject;
#Requests …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个响应gmail pubsub消息的电子邮件解析器.我目前能够接收和解析pubsub消息并解压缩historyId,但是我无法验证我对gmail api的请求.这就是我现在所拥有的:
//function defined outside the scope of the main function
//used to create auth client
function getAuthClient(event, callback) {
var GoogleAuth = require('google-auth-library');
var authFactory = new GoogleAuth();
authFactory.getApplicationDefault(function (err, authClient) {
if (err) {
console.log('Unable to get application default credentials.');
callback(err);
return;
}
// Create the oAuth scopes you need
if (authClient.createScopedRequired && authClient.createScopedRequired()) {
console.log('creating scoped client');
authClient = authClient.createScoped([
'https://mail.google.com/'
]);
}
callback(null, authClient);
});
}
exports.gmailParser = function gmailParser (event, callback) {
var path …Run Code Online (Sandbox Code Playgroud) node.js google-api-nodejs-client gmail-api google-oauth2 google-cloud-functions
所以我只是花了最近几天试图解决这个问题并且问这个问题,以便我可以为其他遇到问题的人解答.
首先,谷歌文档是可怕的,并使用不同的oauth2库,具体取决于您正在查看的许多谷歌API示例.它通常是自相矛盾的,有时直接有代码在其中不起作用.
那好吧.
所以我的问题基本上是:
请参阅下面的答案,了解完整功能的授权流程,从获取初始令牌到保存,稍后加载,刷新和使用它.
干杯.
gmail-api ×10
c# ×2
email ×2
gmail ×2
google-api ×2
decoding ×1
google-oauth ×1
javascript ×1
mime ×1
node.js ×1
powershell ×1
python ×1