无法通过nodejs中的google api发送邮件 [英] Failed sending mail through google api in nodejs
问题描述
我尝试通过Google API发送电子邮件。
我正在使用 googleapis 在node.js中访问Google API。
我的问题是,当我尝试发送没有附件的简单邮件时,我获取以下错误:
$ b
RFC822负载消息字符串或通过/ upload / *上传消息
我没有在我的请求中定义有附件,并且在电子邮件地址中没有看到任何错误。
请帮助。
我的代码:
var google = require('googleapis');
var gmailClass = google.gmail('v1');
var email_lines = [];
email_lines.push(From:\Some Name Here \< rootyadaim@gmail.com>);
email_lines.push(To:hanochg@gmail.com);
email_lines.push('Content-type:text / html; charset = iso-8859-1');
email_lines.push('MIME-Version:1.0');
email_lines.push(主题:这里的新未来主题);
email_lines.push();
email_lines.push(正文发送到这里);
email_lines.push(< b>粗体文本转到< / b>);
var email = email_lines.join(\r\\\
)。trim();
var base64EncodedEmail = new Buffer(email).toString('base64');
gmailClass.users.messages.send({
auth:OAuth2Client,
userId:me,
message:
{
raw:base64EncodedEmail
}
},
function(err,results){});
API。尝试使用以下语法:
gmailClass.users.messages.send({
auth:OAuth2Client,
userId:我,
资源:
{
raw:base64EncodedEmail
}
}
$ b $ p 确保base64EncodedEmail是安全的,你可以使用 base64EncodedEmail.replace(/ \ + / g,' - ')。replace / \ // g,'_')
代码由mscdex发布。此语法适用于v。1.0.11
I'm trying to send an email through Google API.
I'm using googleapis for Google API access in node.js .
My issue is that when I try to send a simple mail with no attachments, I get the following error:
'raw' RFC822 payload message string or uploading message via /upload/* URL required
I didn't define in my request that there is an attachment and I don't see any error in the email addresses.
Please help.
My code:
var google = require('googleapis');
var gmailClass = google.gmail('v1');
var email_lines = [];
email_lines.push("From: \"Some Name Here\" <rootyadaim@gmail.com>");
email_lines.push("To: hanochg@gmail.com");
email_lines.push('Content-type: text/html;charset=iso-8859-1');
email_lines.push('MIME-Version: 1.0');
email_lines.push("Subject: New future subject here");
email_lines.push("");
email_lines.push("And the body text goes here");
email_lines.push("<b>And the bold text goes here</b>");
var email =email_lines.join("\r\n").trim();
var base64EncodedEmail = new Buffer(email).toString('base64');
gmailClass.users.messages.send({
auth: OAuth2Client,
userId: "me",
message:
{
raw: base64EncodedEmail
}
},
function(err, results){});
Changes were made to version 1.0.3 of the google api. Try using the following syntax:
gmailClass.users.messages.send({
auth: OAuth2Client,
userId: "me",
resource:
{
raw: base64EncodedEmail
}
}
Make sure that base64EncodedEmail is url safe. You can use the base64EncodedEmail.replace(/\+/g, '-').replace(/\//g, '_')
code posted by mscdex. This syntax worked for v. 1.0.11
这篇关于无法通过nodejs中的google api发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!