3

This is my code: I tried using an outlook account

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');
  }
});

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.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: my company domain is hosted on Microsoft

  • You can refer this https://stackoverflow.com/questions/48732535/unable-to-authenticate-outlook-address-via-nodemailer if you have outlook account issue and this if it is actually nodemailer issue https://github.com/nodemailer/nodemailer/issues/677#issuecomment-283037667 – Abhijeet Abnave Mar 17 '20 at 10:40

3 Answers3

5

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!

0

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)

JulioSa
  • 118
  • 1
  • 6
0
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);
});
Harsh Lad
  • 9
  • 3