问题
var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');
var transport = nodemailer.createTransport(smtpTransport({
host: 'mail.mydomain.com',
port: 587,
secure: true,
auth: {
user: 'hello',
pass: 'thepassword'
}
}));
var mailOptions = {
from: 'Tester <test@mydomain.com>', // sender address
to: 'someemail@gmail.com', // list of receivers
subject: 'Hello', // Subject line
text: 'hey', // plaintext body
html: 'hey' // html body
};
transport.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
} else {
console.log('Message sent: ' + info.response);
}
});
I am trying to connect to my own postfix server to send an email via SMTP. However, when I run this, I get:
[Error: 139969407567744:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:787: ]
I'm certain that my SMTP port is 587. I'm certain that I have SSL enabled on my Postfix server. I connect through SSL from my Mail app on the Mac.
This is my postfix config:
myhostname = mail.mydomain.com
myorigin = mail.mydomain.com
mydestination = mail.mydomain.com, mydomain.com, localhost, localhost.localdomain
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
alias_maps = hash:/etc/aliases, regexp:/etc/aliases_regex
#alias_database = hash:/etc/aliases
smtpd_tls_CAfile=/etc/postfix/tls/startssl-ca-bundle.pem
smtpd_tls_cert_file=/etc/postfix/tls/mail.mydomain.crt
smtpd_tls_key_file=/etc/postfix/tls/mail.mydomain.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_tls_security_level=may
smtpd_tls_protocols = !SSLv2, !SSLv3
#local_recipient_maps = proxy:unix:passwd.byname $alias_maps
milter_default_action = accept
milter_protocol = 2
smtpd_milters = inet:127.0.0.1:8891
non_smtpd_milters = inet:127.0.0.1:8891
virtual_alias_domains =mydomain.com
virtual_alias_maps = hash:/etc/postfix/virtual
I'm using StartSSL for my Postfix sever. And on my Node.js server, I see this:
StartCom_Certification_Authority_2.pem
StartCom_Certification_Authority_G2.pem
StartCom_Certification_Authority.pem
in /etc/ssl
. So, I am assuming that my Node.js server has the root certificates already installed.
When I run the Node.js code above, I get this on my mail.log
:
Sep 13 04:08:30 d-mail postfix/submission/smtpd[724]: connect from unknown[107.170.206.11]
Sep 13 04:08:30 d-mail postfix/submission/smtpd[724]: lost connection after UNKNOWN from unknown[107.170.206.11]
Sep 13 04:08:30 d-mail postfix/submission/smtpd[724]: disconnect from unknown[107.170.206.11]
I'm not sure why I can't connect from my Node.js app, but I can connect it perfectly fine on my own Macbook.
Do I need to install some certificate on my Node.js server?
回答1:
With port 587 you don't speak SSL directly, but start with plain text and later upgrade to SSL with the STARTTLS command. This means that secure
must be false. See https://github.com/andris9/nodemailer-smtp-transport.
来源:https://stackoverflow.com/questions/25819712/getting-ssl-error-while-sending-email-cant-connect-to-postfix