Node.js gmail发送api在meteor中失败,错误代码为400
我试图在meteor应用程序中使用gmail api发送邮件,返回以下错误Node.js gmail发送api在meteor中失败,错误代码为400,node.js,meteor,gmail-api,Node.js,Meteor,Gmail Api,我试图在meteor应用程序中使用gmail api发送邮件,返回以下错误 Error in calendar insert: Error: failed [400] { "error": { "errors": [ { "domain": "global", "reason": "invalidArgument", "message": "'raw' RFC822 payload message string or uploading message
Error in calendar insert: Error: failed [400] { "error": { "errors": [ { "domain": "global", "reason": "invalidArgument", "message": "'raw' RFC822 payload message string or uploading message via /upload/* URL required" } ], "code": 400, "message": "'raw' RFC822 payload message string or uploading message via /upload/* URL required" } }
我试过下面的方法
"sendGmail": function(str) {
this.unblock();
var url = "https://www.googleapis.com/gmail/v1/users/me/messages/send";
var encodedMail = new Buffer(str).toString("base64").replace(/\+/g, '-').replace(/\//g, '_');
try {
Meteor.http.post(url, {
'headers' : {
'Authorization': "Bearer " + Meteor.user().services.google.accessToken,
'Content-Type': 'application/json'
},
'body': JSON.stringify({
"raw": encodedMail
})
});
} catch(e){
console.log("Error in calendar insert: " + e);
} finally {
return true;
}
}
将以下字符串值作为参数传递:
var str = "Content-Type: text/plain; charset=\"UTF-8\"\n" +
"MIME-Version: 1.0\n" +
"Content-Transfer-Encoding: 7bit\n" +
"to: arunmail2u@gmail.com\n" +
"from: arunsugan08@gmail.com\n" +
"subject: Meteor test mail\n\n" +
"Hi, this is test mail from meteor application";
Meteor.call('sendGmail', str);
正文字符串的形式是
内容
,而不是正文
内容-获取一个普通字符串并将其设置在HTTP请求主体上
非常感谢。数据没有,但是“内容”工作正常:-)@Arun啊,你说得对:)
content
是一个纯字符串,data
获取一个对象,该对象将由库生成字符串。我更新了答案。