Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error sending email using nodemailer via Office365 smtp (MEANjs scaffold)

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?

like image 552
Prasad Silva Avatar asked Apr 23 '15 01:04

Prasad Silva


3 Answers

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: '[email protected]',
      pass: 'FROMUSERPASS'
    },    
  })

  let info = transporter.sendMail({
    from: '[email protected]',
    to: '[email protected]',
    subject: 'Test',
    text: 'hello world',
    html: '<h1>TEST</h1>'
  })
like image 112
Alancode Avatar answered Nov 17 '22 05:11

Alancode


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.

like image 41
Julian Pinn Avatar answered Nov 17 '22 05:11

Julian Pinn


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' }
}
like image 23
Prasad Silva Avatar answered Nov 17 '22 05:11

Prasad Silva