我試圖使用一個服務帳戶和智威湯遜認證發送一封電子郵件,並不斷得到和錯誤有非常無益的消息:{ code: 500, message: null }
失敗發送郵件與googleapis'服務帳戶和JWT的NodeJS權威性
該代碼段是從以下StackOverflow鏈接:Failed sending mail through google api in nodejs
似乎有解決方案是將參數中的密鑰更改爲resource
而不是message
但它不適用於我。這很奇怪,因爲在文檔(https://developers.google.com/gmail/api/v1/reference/users/messages/send)的JS例如,它聲稱關鍵還是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