【问题标题】:How can I send email with my company domain using Nodemailer?如何使用 Nodemailer 向我的公司域发送电子邮件?
【发布时间】:2020-06-28 09:44:49
【问题描述】:

这是我的代码:我尝试使用 Outlook 帐户

const transporter = nodemailer.createTransport({
  host: 'smtp.office365.com',
  auth: {
    user: 'account@mycompanydomain.com',
    pass: 'password'
  }
});

transporter.verify(function(error, success) {
  if (error) {
    console.log(error);
  } else {
    console.log('Server is ready to take our messages');
  }
});

我不确定这里有什么问题。这些是 nodemailer 日志:

[2020-03-17 09:55:34] DEBUG Creating transport: nodemailer (6.4.5; +https://nodemailer.com/; SMTP/6.4.5[client:6.4.5])
[2020-03-17 09:55:34] DEBUG [JAejdt6KMrw] Resolved smtp.office365.com as 40.100.54.194 [cache miss]
[2020-03-17 09:55:35] INFO  [JAejdt6KMrw] Connection established to 40.100.54.194:587
[2020-03-17 09:55:35] INFO  [JAejdt6KMrw] Connection upgraded with STARTTLS
[2020-03-17 09:55:36] DEBUG [JAejdt6KMrw] SMTP handshake finished
[2020-03-17 09:55:41] INFO  [JAejdt6KMrw] User "account@mycompanydomain.com" failed to authenticate
[2020-03-17 09:55:41] DEBUG [JAejdt6KMrw] Closing connection to the server using "end"
Error: Invalid login: 535 5.7.3 Authentication unsuccessful [HK2PR04CA0060.apcprd04.prod.outlook.com]
    at SMTPConnection._formatError (C:\Users\Nonoy\Documents\sample_apps\nodemailer_outlook_integration\node_modules\nodemailer\lib\smtp-connection\index.js:784:19)
    at SMTPConnection._actionAUTHComplete (C:\Users\Nonoy\Documents\sample_apps\nodemailer_outlook_integration\node_modules\nodemailer\lib\smtp-connection\index.js:1523:34)
    at SMTPConnection.<anonymous> (C:\Users\Nonoy\Documents\sample_apps\nodemailer_outlook_integration\node_modules\nodemailer\lib\smtp-connection\index.js:1481:18)
    at SMTPConnection._processResponse (C:\Users\Nonoy\Documents\sample_apps\nodemailer_outlook_integration\node_modules\nodemailer\lib\smtp-connection\index.js:942:20)
    at SMTPConnection._onData (C:\Users\Nonoy\Documents\sample_apps\nodemailer_outlook_integration\node_modules\nodemailer\lib\smtp-connection\index.js:749:14)
    at TLSSocket.SMTPConnection._onSocketData (C:\Users\Nonoy\Documents\sample_apps\nodemailer_outlook_integration\node_modules\nodemailer\lib\smtp-connection\index.js:195:44)
    at TLSSocket.emit (events.js:223:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at TLSSocket.Readable.push (_stream_readable.js:224:10) {
  code: 'EAUTH',
  response: '535 5.7.3 Authentication unsuccessful [HK2PR04CA0060.apcprd04.prod.outlook.com]',
  responseCode: 535,
  command: 'AUTH LOGIN'
}
[2020-03-17 09:55:41] INFO  [JAejdt6KMrw] Connection closed

PS:我的公司域托管在 Microsoft 上

【问题讨论】:

标签: javascript node.js email smtp nodemailer


【解决方案1】:

谢谢你们的回答(都试过了)。但我找到了解决方案。

在我的office365帐户中,我进入设置安全和隐私附加安全验证,点击创建和管理应用密码。然后它将让您生成一个应用程序密码,然后将其用作您的 nodemailer auth 配置密码。如果您有像我这样的身份验证,这也将绕过 2 因素身份验证。

screenshot of settings window here

请注意,您必须立即复制生成的密码。它只会让您复制一次密码。关闭窗口后,您将无法再次查看。

希望这会有所帮助!

【讨论】:

    【解决方案2】:

    请参考nodemaler official documentation !

    即在 transporter 中您缺少 port

    (你可以把它放在host之后)

    port – 是要连接的端口(如果是安全的,则默认为 587 false 或 465 如果为真)

    【讨论】:

      【解决方案3】:
      var nodemailer = require('nodemailer');
      
      // create reusable transporter object using the default SMTP transport
      var transporter = nodemailer.createTransport('smtps://user%40gmail.com:pass@smtp.gmail.com');
      
      // setup e-mail data with unicode symbols
      var mailOptions = {
          from: '"Simple ?" <borntest@foodcita.com>', // sender address
          to: 'serta@foodcita.com, goip@foodcita.com', // list of receivers
          subject: 'Hello ✔', // Subject line
          text: 'Hello world ?', // plaintext body
          html: '<b>Hello world ?</b>' // html body
      };
      
      // send mail with defined transport object
      transporter.sendMail(mailOptions, function(error, info){
          if(error){
              return console.log(error);
          }
          console.log('Message sent: ' + info.response);
      });
      

      【讨论】:

        猜你喜欢
        • 2015-05-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-28
        • 2021-12-28
        相关资源
        最近更新 更多