Я пытаюсь отправить по электронной почте с помощью учетной записи службы и аутентификацию JWT и продолжать получать и ошибку с очень бесполезным сообщением: { code: 500, message: null }
Failed отправки почты с учетной записью службы googleapis' и JWT AUTH в nodejs
Этого фрагмент кода от следующей StackOverflow ссылки: Failed sending mail through google api in nodejs
похоже, что решение было изменить ключ в параметрах для resource
вместо message
, но это не работает для меня. Это странно, потому что в примере JS в документации (https://developers.google.com/gmail/api/v1/reference/users/messages/send) он утверждает, что ключ все еще message
Я аутентичности с
var jwtClient = new google.auth.JWT(config.SERVICE_EMAIL, config.SERVICE_KEY_PATH, null, config.ALLOWED_SCOPES);
затем отправить по электронной почте с
jwtClient.authorize(function(err, res) {
if (err) return console.log('err', err);
var email_lines = [];
email_lines.push("From: \"Some Name Here\" <[email protected]>");
email_lines.push("To: [email protected]");
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 base64EncodedEmailSafe = new Buffer(email).toString('base64').replace(/\+/g, '-').replace(/\//g, '_');
var params = {
auth: jwtClient,
userId: "[email protected]",
resource: {
raw: base64EncodedEmailSafe
}
};
gmail.users.messages.send(params, function(err, res) {
if (err) console.log('error sending mail', err);
else console.log('great success', res);
});
}
комментарии в библиотеке, похоже, говорят, что ресурс является правильным свойством (https://github.com/google/google-api-nodejs-client/blob/master/apis/gmail/v1.js)
Что мне не хватает?
[Только что открыли проблему в github] (https://github.com/google/google-api-nodejs-client/issues/347) – dthareja