Nodemailer and “SSL23_GET_SERVER_HELLO:unknown protocol” error

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: '[email protected]',
        pass: 'mypassword'
    },
    tls: {ciphers: "SSLv3"}
}));

How to solve this error?

Answers:

Answer

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"
        }
      }
    }); 
Answer

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);
            }
        });
    });
};
Answer

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'
    }
});
Answer

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();
        });
Answer

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

TLS Protocol: ON,
    auth: {
        user: '[email protected]',
        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.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.