Nodemail x Node.js:身份验证失败,但已成功测试

时间:2019-12-05 18:16:21

标签: node.js firebase google-cloud-functions nodemailer

我遇到了应该通过SMTP传输器发送电子邮件的nodemailer Firebase Function问题。

这很奇怪,因为我正在使用以下方法测试我的连接是否成功:

// check server readiness
const serverReady = await new Promise<boolean>(resolve => {
  transporter.verify( (err: any, succ: any) => {
    if (err) {
      console.log(err);
      resolve(false);
    } else {
      console.log('Server is ready to take our messages');
      resolve(true);
    }
  });
})

哪个打印Server is ready to take our messages

然后设置信封并使用.sendMail方法发送信封后,出现此错误:

Unhandled error { Error: Mail command failed: 530 5.5.1 Authentication Required.
    at SMTPConnection._formatError (/srv/node_modules/nodemailer/lib/smtp-connection/index.js:777:19)
    at SMTPConnection._actionMAIL (/srv/node_modules/nodemailer/lib/smtp-connection/index.js:1546:34)
    at SMTPConnection._responseActions.push.str (/srv/node_modules/nodemailer/lib/smtp-connection/index.js:1028:18)
    at SMTPConnection._processResponse (/srv/node_modules/nodemailer/lib/smtp-connection/index.js:935:20)
    at SMTPConnection._onData (/srv/node_modules/nodemailer/lib/smtp-connection/index.js:742:14)
    at TLSSocket.SMTPConnection._onSocketData.chunk (/srv/node_modules/nodemailer/lib/smtp-connection/index.js:195:44)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at TLSSocket.Readable.push (_stream_readable.js:208:10)
    at TLSWrap.onread (net.js:601:20)
  code: 'EENVELOPE',
  response: '530 5.5.1 Authentication Required.',
  responseCode: 530,
  command: 'MAIL FROM' }

错误非常明显:Failed Auth,但是自测试开始以来很奇怪!

连接参数为:

// options to connect to server
const smtpOptions = {
  host: 'smtp.zoho.eu',
  port: 465,
  secure: true,
  auth: {
    user: functions.config().nodemailer.user,
    pass: functions.config().nodemailer.pass
  }
};

// transporter for sending the email
const transporter = nodeMail.createTransport( smtpOptions );

谢谢大家

2 个答案:

答案 0 :(得分:0)

transporter.verify仅测试连接和身份验证,看起来您无权使用特定的MAIL FROM地址。

答案 1 :(得分:0)

有人找到修复程序吗?我在Zoho + Nodemailer中遇到同样的问题。我尝试了一些设置,包括SSL / TLS,应用程序密码,用户密码,创建了一个新帐户,然后将其用作from电子邮件。似乎没有任何作用。