发送电子邮件时出现 SSL 错误,无法连接到 Postfix [英] Getting SSL error while sending email, can't connect to Postfix

查看:143
本文介绍了发送电子邮件时出现 SSL 错误,无法连接到 Postfix的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var nodemailer = require('nodemailer');var smtpTransport = require('nodemailer-smtp-transport');var 传输 = nodemailer.createTransport(smtpTransport({主机:'mail.mydomain.com',端口:587,安全:真实,授权:{用户:'你好',通过:'密码'}}));var 邮件选项 = {from: 'Tester ',//发件人地址to: 'someemail@gmail.com',//收件人列表subject: '你好',//主题行text: 'hey',//纯文本正文html: '嘿'//html 正文};transport.sendMail(mailOptions, function (error, info) {如果(错误){控制台日志(错误);} 别的 {console.log('消息发送:' + info.response);}});

我正在尝试连接到我自己的 postfix 服务器以通过 SMTP 发送电子邮件.但是,当我运行它时,我得到:

[错误:139969407567744:错误:140770FC:SSL 例程:SSL23_GET_SERVER_HELLO:未知协议:../deps/openssl/openssl/ssl/s23_clnt.c:787:]

我确定我的 SMTP 端口是 587.我确定我在 Postfix 服务器上启用了 SSL.我从 Mac 上的邮件应用通过 SSL 连接.

这是我的后缀配置:

myhostname = mail.mydomain.commyorigin = mail.mydomain.commydestination = mail.mydomain.com, mydomain.com, localhost, localhost.localdomain中继主机 =我的网络 = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128邮箱大小限制 = 0收件人分隔符 = +inet_interfaces = 全部alias_maps = hash:/etc/aliases, regexp:/etc/aliases_regex#alias_database = hash:/etc/aliasessmtpd_tls_CAfile=/etc/postfix/tls/startssl-ca-bundle.pemsmtpd_tls_cert_file=/etc/postfix/tls/mail.mydomain.crtsmtpd_tls_key_file=/etc/postfix/tls/mail.mydomain.keysmtpd_use_tls=yessmtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scachesmtp_tls_session_cache_database = btree:${data_directory}/smtp_scachesmtpd_tls_security_level=可能smtpd_tls_protocols = !SSLv2, !SSLv3#local_recipient_maps = proxy:unix:passwd.byname $alias_mapsmilter_default_action = 接受milter_protocol = 2smtpd_milters = inet:127.0.0.1:8891non_smtpd_milters = inet:127.0.0.1:8891virtual_alias_domains =mydomain.comvirtual_alias_maps = 哈希:/etc/postfix/virtual

我将 StartSSL 用于我的 Postfix 服务器.在我的 Node.js 服务器上,我看到了:

StartCom_Certification_Authority_2.pemStartCom_Certification_Authority_G2.pemStartCom_Certification_Authority.pem

/etc/ssl 中.所以,我假设我的 Node.js 服务器已经安装了根证书.

当我运行上面的 Node.js 代码时,我在我的 mail.log 上看到了这个:

Sep 13 04:08:30 d-mail postfix/submission/smtpd[724]: connect from unknown[107.170.206.11]9 月 13 日 04:08:30 d-mail postfix/submission/smtpd[724]:从未知 [107.170.206.11] UNKNOWN 后丢失连接9 月 13 日 04:08:30 d-mail postfix/submission/smtpd[724]:断开与未知 [107.170.206.11]

我不知道为什么我无法从我的 Node.js 应用程序连接,但我可以在我自己的 Macbook 上完美地连接它.

我需要在我的 Node.js 服务器上安装一些证书吗?

解决方案

使用 587 端口时,您不会直接使用 SSL,而是从纯文本开始,然后使用 STARTTLS 命令升级到 SSL.这意味着 secure 必须为 false.请参阅https://github.com/andris9/nodemailer-smtp-transport.>

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?

解决方案

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.

这篇关于发送电子邮件时出现 SSL 错误,无法连接到 Postfix的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆