Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodemailer 2.x configuration for Office 365 direct send

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?

like image 800
David Williamson Avatar asked Jul 04 '16 20:07

David Williamson


People also ask

How do I set up Direct Send in Office 365?

Step-by-step instructions for direct sendSign in to the Microsoft 365 admin center. Go to Settings > Domains, select your domain (for example, contoso.com), and find the MX record. The MX record will have data for Points to address or value that looks similar to contoso-com.mail.protection.outlook.com .

Can Office 365 Shared Mailbox use SMTP?

Save this answer. Show activity on this post. Office 365 Shared Mailboxes (user without Exhcange licence) do not have SMTP access to Exchange online, which is a bit different from behaviour you might expect when coming from on premise Exchange.

How do I send an email from Outlook to Nodemailer?

In short, what you need to do to send messages, would be the following: Create a Nodemailer transporter using either SMTP or some other transport mechanism. Set up message options (who sends what to whom) Deliver the message object using the sendMail() method of your previously created transporter.


3 Answers

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
like image 63
Julian Pinn Avatar answered Oct 11 '22 15:10

Julian Pinn


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.

like image 35
Vignesh T.V. Avatar answered Oct 11 '22 17:10

Vignesh T.V.


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

like image 3
John Bedoya Avatar answered Oct 11 '22 16:10

John Bedoya