最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I send email with my company domain using Nodemailer? - Stack Overflow

programmeradmin0浏览0评论

This is my code: I tried using an outlook account

const transporter = nodemailer.createTransport({
  host: 'smtp.office365',
  auth: {
    user: '[email protected]',
    pass: 'password'
  }
});

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

Im not sure what is the problem over here. These are the nodemailer logs:

[2020-03-17 09:55:34] DEBUG Creating transport: nodemailer (6.4.5; +/; SMTP/6.4.5[client:6.4.5])
[2020-03-17 09:55:34] DEBUG [JAejdt6KMrw] Resolved smtp.office365 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 "[email protected]" 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]
    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]',
  responseCode: 535,
  mand: 'AUTH LOGIN'
}
[2020-03-17 09:55:41] INFO  [JAejdt6KMrw] Connection closed

PS: my pany domain is hosted on Microsoft

This is my code: I tried using an outlook account

const transporter = nodemailer.createTransport({
  host: 'smtp.office365.',
  auth: {
    user: '[email protected]',
    pass: 'password'
  }
});

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

Im not sure what is the problem over here. These are the nodemailer logs:

[2020-03-17 09:55:34] DEBUG Creating transport: nodemailer (6.4.5; +https://nodemailer./; SMTP/6.4.5[client:6.4.5])
[2020-03-17 09:55:34] DEBUG [JAejdt6KMrw] Resolved smtp.office365. 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 "[email protected]" 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.]
    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.]',
  responseCode: 535,
  mand: 'AUTH LOGIN'
}
[2020-03-17 09:55:41] INFO  [JAejdt6KMrw] Connection closed

PS: my pany domain is hosted on Microsoft

Share Improve this question asked Mar 17, 2020 at 10:14 Juan Miguel LadislaJuan Miguel Ladisla 1231 silver badge7 bronze badges 1
  • You can refer this stackoverflow./questions/48732535/… if you have outlook account issue and this if it is actually nodemailer issue github./nodemailer/nodemailer/issues/… – Abhijeet Abnave Commented Mar 17, 2020 at 10:40
Add a ment  | 

3 Answers 3

Reset to default 7

Thank you for your answers guys (tried them all). But I found the solution.

In my office365 account, I went to the settings, Security & Privacy, Additional security verification, clicked on Create and manage app passwords. Then it will let you generate an app password that you will then use as your nodemailer auth config password. This will also bypass the 2-factor authentication if you have one like mine.

screenshot of settings window here

Note that you must copy the generated password immediately. It will only let you copy the password once. Upon closing the window, you can't view it again.

Hope this helps!

Please refer to nodemaler official documentation !

Namely in transporter you are missing the port value

(you may put it just after the host)

port – is the port to connect to (defaults to 587 if is secure is false or 465 if true)

var nodemailer = require('nodemailer');

// create reusable transporter object using the default SMTP transport
var transporter = nodemailer.createTransport('smtps://user%40gmail.:[email protected]');

// setup e-mail data with unicode symbols
var mailOptions = {
    from: '"Simple ?" <[email protected]>', // sender address
    to: '[email protected], [email protected]', // 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);
});
发布评论

评论列表(0)

  1. 暂无评论