javascript Nodemailer 和“SSL23_GET_SERVER_HELLO:未知协议”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33102313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Nodemailer and "SSL23_GET_SERVER_HELLO:unknown protocol" error
提问by
Below is my Node.js code. Using the code results in:
下面是我的 Node.js 代码。使用代码导致:
Error: 0:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:openssl\ssl\s23_clnt.c:794
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?
如何解决这个错误?
采纳答案by Avanish Kumar
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"
}
}
});
回答by Mike Cheel
I had this error using a third party smtp with the 'nodemailer-smtp-transport' node module.
我使用带有“ nodemailer-smtp-transport”节点模块的第三方 smtp 时出现此错误。
My problem turned out to be that I was using port 587.
我的问题原来是我使用的是 587 端口。
When I switched it to 465 it all started working.
当我将它切换到 465 时,一切都开始工作了。
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):
还有我的电子邮件功能(打字稿,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);
}
});
});
};
回答by Mohammed Essehemy
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'
}
});
回答by tier1
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.
看起来你让它变得比它需要的更复杂一些。我在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();
});
回答by jww
Your problem is likely SSLv3. Most servers have it disabled.
您的问题很可能是 SSLv3。大多数服务器都禁用了它。
TLS Protocol: ON,
auth: {
user: '[email protected]',
pass: 'super-secret-password'
},
tls: {ciphers: "SSLv3"}
You should use TLS 1.0 and above.
您应该使用 TLS 1.0 及更高版本。
You should also use use Server Name Indication or SNI, but I don't know how to tell Node.js to use it.
您还应该使用 use Server Name Indication 或 SNI,但我不知道如何告诉 Node.js 使用它。