可以在chrome扩展中使用gmail api吗?
我想写一个 chrome 扩展,可以发送带有附件的电子邮件。
我已经环顾了好几天了,但我无法让 gmail api 在我的 chrome 扩展中工作。
从根本上来说,可以从 Chrome 扩展程序发送电子邮件吗?我看到很多帖子说我不能这样做,因为我无法单独从客户端 JavaScript 发送电子邮件。所以我需要切换到像node.js这样的东西?
不过,Chrome 扩展程序网上商店中的一些扩展程序可以与我的 Gmail 收件箱配合使用。 (例如这个:https://chrome.google。 com/webstore/detail/checker-plus-for-gmail/oeopbcgkkoapgobdbedcemjljbihmemj)
最后开始发送电子邮件。太感谢了!
背景.js
window.onload = chrome.identity.getAuthToken({ 'interactive': true }, function(token,grantedScopes) {
console.log(token);
console.log(grantedScopes);
chrome.storage.local.set({oauth2token: token}, function() {});
var currentSessionAccessToken = token;
var x = new XMLHttpRequest();
x.open('GET','https://www.googleapis.com/oauth2/v2/userinfo?alt=json&access_token=' + token);
x.onload = function() {
console.log(x.response);
};
x.send();
var y = new XMLHttpRequest();
y.open('GET','https://gmail.googleapis.com/gmail/v1/users/me/labels?alt=json&access_token=' + token);
y.onload = function() {
console.log(y.response);
};
y.send();
var z = new XMLHttpRequest();
z.open(
'POST',
'https://gmail.googleapis.com/gmail/v1/users/me/messages/send?alt=json&access_token=' + token,
{"raw": "the email raw"
});
z.setRequestHeader('Authorization', 'Bearer/' + token);
z.setRequestHeader('Accept', 'application/json');
z.setRequestHeader('Content-Type', 'application/json');
z.onload = function() {
console.log(z.response);
};
z.send(
JSON.stringify({"raw": "the email raw"}
));
})
I want to write a chrome extension that can send emails with attachments.
I have looked around for days and I can't get gmail api working in my chrome extension.
Fundamentally is it possible to send email from a chrome extension? I came across a lot of posts saying I can't do that because I cannot send email from client-side javascript alone. So I need to switch to something like node.js?
However, there are extensions from the Chrome extension webstore that can work with my gmail inbox. (for example this one: https://chrome.google.com/webstore/detail/checker-plus-for-gmail/oeopbcgkkoapgobdbedcemjljbihmemj)
Finally get the email sending going on. Thank you so much!
background.js
window.onload = chrome.identity.getAuthToken({ 'interactive': true }, function(token,grantedScopes) {
console.log(token);
console.log(grantedScopes);
chrome.storage.local.set({oauth2token: token}, function() {});
var currentSessionAccessToken = token;
var x = new XMLHttpRequest();
x.open('GET','https://www.googleapis.com/oauth2/v2/userinfo?alt=json&access_token=' + token);
x.onload = function() {
console.log(x.response);
};
x.send();
var y = new XMLHttpRequest();
y.open('GET','https://gmail.googleapis.com/gmail/v1/users/me/labels?alt=json&access_token=' + token);
y.onload = function() {
console.log(y.response);
};
y.send();
var z = new XMLHttpRequest();
z.open(
'POST',
'https://gmail.googleapis.com/gmail/v1/users/me/messages/send?alt=json&access_token=' + token,
{"raw": "the email raw"
});
z.setRequestHeader('Authorization', 'Bearer/' + token);
z.setRequestHeader('Accept', 'application/json');
z.setRequestHeader('Content-Type', 'application/json');
z.onload = function() {
console.log(z.response);
};
z.send(
JSON.stringify({"raw": "the email raw"}
));
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论