我正在使用Gmail API发送电子邮件。但得到一个错误:
未捕获的TypeError:无法读取未定义的属性“用户”
<script type="text/javascript">
function sendMessage(email, callback) {
// Web-safe base64
var base64EncodedEmail = btoa(email).replace(/\//g, '_').replace(/\+/g, '-');
var request = gapi.client.gmail.users.messages.send({
'userId': 'me',
'message': {
'raw': base64EncodedEmail
}
});
request.execute(callback);
}
function send() {
var to = 'vijay@itsabacus.com',
subject = 'Hello World',
content = 'send a Gmail.'
var email = "From: 'me'\r\n" +
"To: " + to + "\r\n" +
"Subject: " + subject + "\r\n" +
"\r\n" +
content;
sendMessage(email, function () {
console.log(arguments);
});
}
</script>
答案 0 :(得分:0)
我遇到了同样的问题,对我来说,我需要做类似以下的事情:
gapi.load('client:auth2', () => {
gapi.client.load('gmail', 'v1', () => {
console.log('Loaded Gmail');
});
}
之后在调试器中我可以像上面一样使用gmail api:
gapi.client.gmail.users.messages.send({...});
希望这有帮助。