Nodemailer和“SSL23_GET_SERVER_HELLO:未知协议”错误

时间:2015-10-13 12:07:46

标签: javascript node.js ssl openssl

下面是我的Node.js代码。使用代码导致:

  

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

以下是代码:

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

如何解决此错误?

5 个答案:

答案 0 :(得分:10)

我使用带有' nodemailer-smtp-transport '节点模块的第三方smtp时出现此错误。

我的问题原来是我使用的是端口587.

当我把它切换到465时,一切都开始工作了。

我的配置如下:

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

我的电子邮件功能(打字稿,蓝鸟承诺):

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

答案 1 :(得分:5)

我遇到过类似的问题

使用此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'
    }
});

答案 2 :(得分:1)

使用此功能

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

答案 3 :(得分:0)

看起来你的制作比它需要的要复杂一些。我在Nodemailer的0.7.0版本中成功使用了它。

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

答案 4 :(得分:0)

您的问题可能是SSLv3。 Most servers have it disabled

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

您应该使用TLS 1.0及以上版本。

您还应该使用Server Name Indication or SNI,但我不知道如何告诉Node.js使用它。