我正在设置服务器,以使用nodemailer通过gmail发送电子邮件。我可以使用新的访问令牌发送电子邮件,但过期后将无法使用。返回的错误只是说“错误:无效的状态代码400”。当前在本地主机上。
我尝试为访问令牌提供“ expires”字段,并在消息本身中提供身份验证,并使用其他刷新令牌。我无法以任何方式刷新令牌。由于我能够使用新的访问令牌发送电子邮件,因此我觉得其余配置是正确的。
var nodemailer = require('nodemailer')
var auth = {
type: "OAuth2",
user: "xxxxxxx@gmail.com",
clientID: "27xxxxxxxxxxxxxxxxxxxx6.apps.googleusercontent.com",
clientSecret: "S6xxxxxxxxxxxR",
// With only refresh token - BAD
refreshToken: "1/hdxxxxxxxxxxxxxxxxxPDWFg",
// With a fresh access token - OK
// accessToken: "ya29.GlsUB5xxxxxxxxxxxxxxxxxxxxzuL2uYUvF5",
// With both accessToken and expires - BAD
// expires: 1558728453
}
var transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: auth,
})
//makeEmail is a function that creates the message object.
transporter.sendMail(makeEmail(config.email, id, false, errorpath), function(err, info){
if(err){
console.log(`emailing got this error:
${err}
code:${err.code}
response:${err.response}
responseCode:${err.responseCode}`)
console.log(`and this stuff ${info}`)
}
else{
console.log('at least the email worked.')
}
})
运行sendMail()的输出是:
Error: Invalid status code 400
code:EAUTH
response:undefined
responseCode:undefined
and this stuff undefined