11

Below is my Node.js code. Using the code results in:

Error: 0:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:openssl\ssl\s23_clnt.c:794

Here is the code:

var express = require('express')    
  , fs = require("fs")
  , app = express()
  , path = require('path')
  , request = require('request')
  , bodyParser = require('body-parser')
  , http = require('http')
  , server = http.createServer(app)
  , io = require('socket.io').listen(server, {log: true,    origins: '*:*'})
;

var smtpTransport = require('nodemailer-smtp-transport');
var options = {
   key  : fs.readFileSync('server.key'),
   cert : fs.readFileSync('server.crt')
};
var nodemailer = require('nodemailer');
var sendmailTransport = require('nodemailer-sendmail-transport');      

    var emailserver = nodemailer.createTransport(smtpTransport({
    service: 'Gmail',
    port: 25,
    strictSSL: false,
    host:'smtp.gmail.com',
    SSL Protocol: 'off',
TLS Protocol: ON,
    auth: {
        user: 'choudhary1707@gmail.com',
        pass: 'mypassword'
    },
    tls: {ciphers: "SSLv3"}
}));

How to solve this error?

jww
  • 97,681
  • 90
  • 411
  • 885
  • Possible duplicate of [SSL23\_GET\_SERVER\_HELLO:unknown protocol \[connection to msa (587) port\]](http://stackoverflow.com/questions/22462819/ssl23-get-server-hellounknown-protocol-connection-to-msa-587-port) – apapa Dec 15 '15 at 08:01
  • Possible duplicate of [node-request - Getting error "SSL23\_GET\_SERVER\_HELLO:unknown protocol"](http://stackoverflow.com/questions/15421050/node-request-getting-error-ssl23-get-server-hellounknown-protocol) – Stephen Melvin Mar 18 '16 at 16:32

5 Answers5

10

I had this error using a third party smtp with the 'nodemailer-smtp-transport' node module.

My problem turned out to be that I was using port 587.

When I switched it to 465 it all started working.

My configuration looks like:

const smtpConfiguration = {
    host: '<my smtp host>',
    port: 465,
    secure: true, // use TLS
    auth: {
        user: '<user account>',
        pass: '<password>'
    }
};

And my email function (typescript, bluebird Promise):

export const SendEmail = (from:string,
                          to:string[],
                          subject:string,
                          text:string,
                          html:string) => {

    const transportOptions = smtpConfiguration;

    const transporter = nodemailer.createTransport(smtpTransport(transportOptions));

    const emailOptions = {
        from: from,
        to: to.join(','),
        subject: subject,
        text: text,
        html: html
    };

    return new Promise((resolve, reject) => {
        transporter.sendMail(emailOptions, (err, data) => {
            if (err) {
                return reject(err);
            } else {
                return resolve(data);
            }
        });
    });
};
Mike Cheel
  • 12,626
  • 10
  • 72
  • 101
6

I've faced similar problem

solved with this thread

// For port 465
var transporter = nodemailer.createTransport({
    host: 'smtp.hostname',
    port: 465,
    secure: true,
    auth: {
        user: 'email',
        pass: 'password'
    }
});

// for port 587 or 25 or 2525 etc.
var transporter = nodemailer.createTransport({
    host: 'smtp.hostname',
    port: 587,
    secure: false,
    requireTLS: true, // only use if the server really does support TLS
    auth: {
        user: 'email',
        pass: 'password'
    }
});
Mohammed Essehemy
  • 2,006
  • 1
  • 16
  • 20
1

Use this this is working

var nodemailer = require('nodemailer');

      var smtpTransport = nodemailer.createTransport("SMTP", {
      service: "Gmail",
      connectionTimeout : "7000",
      greetingTimeout : "7000",

      auth: {
        XOAuth2: { 
          user: "email id",
            clientId: "client id",
            clientSecret: "secret",
            refreshToken: "refresh token"
        }
      }
    }); 
A.K.
  • 2,284
  • 3
  • 26
  • 35
0

Looks like your making it a little more complicated than it needs to be. I'm successfully using this with version 0.7.0 of Nodemailer.

var smtpTransport = nodemailer.createTransport("SMTP", {
            service: "Gmail",
            auth: {
                user: "***@gmail.com",
                pass: "****"
            }
        });

        var mailOptions = {
            from: "****@gmail.com",
            to: to,
            subject: 'Subject Line!',
            text: 'Alternate Text',
            html: '<label>Hello!</label>'
        }

        smtpTransport.sendMail(mailOptions, function(error, response) {
            if (error) {
                console.log(error);
            } else {
                console.log("Message sent: " + response.message);
            }

            // if you don't want to use this transport object anymore, uncomment following line
            smtpTransport.close(); // shut down the connection pool, no more messages

            callback();
        });
tier1
  • 6,303
  • 6
  • 44
  • 75
  • Yes it does. I'm using it on a production server. What is the exact error your getting with this and what version of node are you using? – tier1 Oct 13 '15 at 13:13
  • 1
    i am using http server on localhost. Second Question is how to create https server on localhost –  Oct 14 '15 at 04:39
0

Your problem is likely SSLv3. Most servers have it disabled.

TLS Protocol: ON,
    auth: {
        user: 'jdoe@example.com',
        pass: 'super-secret-password'
    },
    tls: {ciphers: "SSLv3"}

You should use TLS 1.0 and above.

You should also use use Server Name Indication or SNI, but I don't know how to tell Node.js to use it.

jww
  • 97,681
  • 90
  • 411
  • 885