12

I'm trying to use Office365 SMTP to send email using Nodemailer (in a MEANjs scaffold), but I get the following error:

[Error: 140735277183760:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:795:]

I'm using the following Nodemailer options:

{ 
    host: 'smtp.office365.com',
    port: '587',
    auth: { user: 'xxxx', pass: 'xxxx' },
    secure: 'false',
    tls: { ciphers: 'SSLv3' }
}

Removing the tls field doesn't make a difference. What am I missing?

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Prasad Silva
  • 1,020
  • 2
  • 11
  • 28

4 Answers4

23

The solution was simple. The 'secure' field should be 'secureConnection'. The MEANjs scaffold that generated the configs created mailer options with the 'secure' field. The rest of the options are fine. For anyone that needs a working Office365 SMTP nodemailer options block, the following should work:

{ 
    host: 'smtp.office365.com',
    port: '587',
    auth: { user: 'xxxx', pass: 'xxxx' },
    secureConnection: false,
    tls: { ciphers: 'SSLv3' }
}
BrettJ
  • 6,801
  • 1
  • 23
  • 26
Prasad Silva
  • 1,020
  • 2
  • 11
  • 28
  • When I tried using the opts you supplied it didn't worked and gave a timeout error. I had to remove the `secureConnection` opt for it to work. Thank you! – João Cerqueira Jun 14 '16 at 11:00
  • thank you very much! in my case it worked with this setting: `"secure": false, "tls": { "ciphers": "SSLv3" }` – rdenisi Sep 06 '17 at 10:31
18

I know this is old but if anyone looks this up in 2019, you can just add service: "Outlook365"

and you won't have to specify connection options.

Node Mailer Docs

let transporter = nodemailer.createTransport({
    service: "Outlook365",
    auth: {
      user: 'FROMUSER@office365.com',
      pass: 'FROMUSERPASS'
    },    
  })

  let info = transporter.sendMail({
    from: 'FROMUSER@office365.com',
    to: 'TOUSER@office365.com',
    subject: 'Test',
    text: 'hello world',
    html: '<h1>TEST</h1>'
  })
Alancode
  • 181
  • 1
  • 3
7

This nodemailer documentation https://nodemailer.com/2-0-0-beta/setup-smtp/ indeed states options.secure and not options.secureConnection. It also suggests, in an example, that options.secure is expecting a boolean value true or false and not a string value 'true' or 'false'. Removing the '' from around 'false' works for me.

Simon H
  • 2,495
  • 4
  • 30
  • 38
Julian Pinn
  • 470
  • 5
  • 6
  • 2
    I'm new to stackoverflow. I'm wondering why the down-vote for a valid answer. All Simon H did was put grey boxes around some of the text. Harsh when my intension is to help people. – Julian Pinn Oct 01 '16 at 05:17
0

My problem was that the username and password were spelled correctly but I did not login in the Account after creation. So I used a mail program (Thunderbird) to login once and had to change my password and then I had access over Nodemailer.

Mare Seestern
  • 335
  • 1
  • 3
  • 13