我正在尝试使用 JavaScript 通过 Google API 发送电子邮件。
我的问题是,当我尝试发送不带附件的简单邮件时,出现以下错误:
'raw' RFC822 有效负载消息字符串或通过 /upload/* URL 需要上传消息`
我的代码
function sendMessage() {
gapi.client.load('gmail', 'v1', function() {
// Web-safe base64
var to = 'someone@someone.nl',
subject = 'Hello World',
content = 'send a Gmail.'
var base64EncodedEmail = btoa(
"Content-Type: text/plain; charset=\"UTF-8\"\n" +
"Content-length: 5000\n" +
"Content-Transfer-Encoding: message/rfc2822\n" +
"to: someone@someone.nl\n" +
"from: \"test\" <test@gmail.com>\n" +
"subject: Hello world\n\n" +
"The actual message text goes here"
).replace(/\+/g, '-').replace(/\//g, '_');
var mail= base64EncodedEmail;
console.log(mail);
var request = gapi.client.gmail.users.messages.send({
'userId': "me",
'message': {
'raw': mail
}
});
request.execute(function(response){
console.log(response);
});
});
}