11

I'm using nodemailer v2.4.2 with node.js v4.4.7 and I want to send emails from my server via my Office 365 SMTP mail server. I'm using the smtpTransport v2.5.0 with this configuration:

var transporter = nodemailer.createTransport(smtpTransport({
  host: 'smtp.office365.com',
  port: 25, // have tried 465
  secureConnection: secure,
  auth: {
    user: username,
    pass: password
  },
  tls: {
    rejectUnauthorized: false // don't verify certificates
  },
  ignoreTLS: false // don't turn off STARTTLS support
}));

I've tried specifying an authMethod of LOGIN and PLAIN but neither make any difference. When I try and send an email I get an error:

[Error: Invalid login: 504 5.7.4 Unrecognized authentication type]
code: 'EAUTH',
response: '504 5.7.4 Unrecognized authentication type',
responseCode: 504

Does anyone have any idea on what authorization type is expected by Office 365 and whether I need to specify any different settings in the nodemailer setup?

1

5 Answers 5

37

This works for me:

    var transporter = nodemailer.createTransport({
        host: 'smtp.office365.com', // Office 365 server
        port: 587,     // secure SMTP
        secure: false, // false for TLS - as a boolean not string - but the default is false so just remove this completely
        auth: {
            user: username,
            pass: password
        },
        tls: {
            ciphers: 'SSLv3'
        }
    });

You may like to add:

    requireTLS: true
3
  • This works, and the explanations were very helpful. thanks Jul 4, 2018 at 9:07
  • 1
    secure:false and adding requireTLS: true works for me, thankyou Jul 7, 2020 at 17:48
  • requireTLS: true was not required for. Thanks!!
    – JRichardsz
    Aug 5, 2022 at 0:15
3
var transporter = nodemailer.createTransport({
                  host: "smtpout.secureserver.net",
                  port: 587,
                  secureConnection: false,
                  secure: false,
                  requireTLS: true,
                  auth: {
                    user: emailUsr,
                    pass: emailPass
                  },
                  tls: {
                    rejectUnauthorized: false
                  }
                });

You can try with this configuration

1

A very late answer but if you are using a shared mailbox from Office365, you won't be able to authenticate via SMTP. I also got this error and then realized this.

Refer Can Office365 shared mailbox use SMTP? for information on this.

0

In my scenario I had to make sure the email field From was using the same email address I used for the mailbox login - in the options object at: auth.user.

This way, provided I was using the TLS details for STARTTLS e.g. auth.user.secure: false, requireTLS: true and tls.ciphers: 'SSLv3', I managed to send an email with Nodemailer.

0
let testAccount = await nodemailer.createTestAccount();
      let transporter = nodemailer.createTransport({
        service: "Outlook365",
        host: 'smtp.office365.com',
        port: '587',
        tls: {
          ciphers:'SSLv3',
          rejectUnauthorized: false 
        },
        auth: {
            user: "",
            pass: ""
        }
      });

You can use the office 365/outlook configuration with node-mailer to send mail using outlook account –

1
  • You can use the office 365/outlook configuration with node-mailer to send mail using outlook account Aug 13, 2021 at 3:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.