albertito / chasquid

SMTP (email) server with a focus on simplicity, security, and ease of operation [mirror]

Home Page:https://blitiri.com.ar/p/chasquid/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Connection unexpectedly closed: [Errno 104] Connection reset by peer

hyahm opened this issue · comments

os: centos 7
go version: go1.12.7 linux/amd64

install

git clone https://blitiri.com.ar/repos/chasquid
cd chasquid
make
make install-binaries
make install-config-skeleton

add user

chasquid-util user-add cander@hyahm.com --password=123456

I had register a https cert and repalce it

cp 3339730_mail.hyahm.com.key fullchain.pem
cp 3339730_mail.hyahm.com.pem privkey.pem

start service

systemctl restart chasquid

tree of /etc/chasquid

[root@hyahm chasquid]# tree
.
├── certs -> /etc/letsencrypt/live/
├── chasquid.conf
├── domains
│   └── hyahm.com
│       └── users
├── hooks
│   └── post-data
└── README
[root@hyahm certs]# pwd
/etc/chasquid/certs
[root@hyahm certs]# tree
.
└── hyahm.com
    ├── 3339730_mail.hyahm.com.key
    ├── 3339730_mail.hyahm.com_nginx.zip
    ├── 3339730_mail.hyahm.com.pem
    ├── cert.pem -> ../../archive/hyahm.com/cert2.pem
    ├── chain.pem -> ../../archive/hyahm.com/chain2.pem
    ├── fullchain.pem -> ../../archive/hyahm.com/fullchain2.pem
    ├── privkey.key
    └── privkey.pem -> ../../archive/hyahm.com/privkey2.pem

1 directory, 8 files

[root@hyahm domains]# ls
hyahm.com
[root@hyahm domains]# tree
.
└── hyahm.com
    └── users

1 directory, 1 file

check

[root@hyahm domains]# smtp-check hyahm.com
2020/01/06 12:11:31 === STS policy
2020/01/06 12:11:31 Not available (MTA-STS TXT record missing)
2020/01/06 12:11:31 
2020/01/06 12:11:31 === MX:  1  mail.hyahm.com.
2020/01/06 12:11:33 SPF fail for 120.26.164.125: matched 'all'
2020/01/06 12:11:34 read tcp 120.26.164.125:45182->120.26.164.125:25: read: connection reset by peer

python client code

#!/usr/bin/python3
 
import smtplib
from email.mime.text import MIMEText
from email.header import Header
 
# 第三方 SMTP 服务
mail_host="mail.hyahm.com"  #设置服务器
mail_user="cander@hyahm.com"    #用户名
mail_pass="123456"   #口令 
 
 
sender = 'cander@hyahm.com'
receivers = ['727023460@qq.com']  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
 
message = MIMEText('Python 邮件发送测试...', 'plain', 'utf-8')
message['From'] = Header("菜鸟教程", 'utf-8')
message['To'] =  Header("测试", 'utf-8')
 
subject = 'Python SMTP 邮件测试'
message['Subject'] = Header(subject, 'utf-8')
 
 
try:
    smtpObj = smtplib.SMTP() 
    smtpObj.connect(mail_host, 465)    # 25 为 SMTP 端口号
    smtpObj.login(mail_user,mail_pass)
    smtpObj.sendmail(sender, receivers, message.as_string())
    print ("邮件发送成功")
except smtplib.SMTPException as e:
    print(e)
    print ("Error: 无法发送邮件")

Thanks for the bug report and for all the details! Some questions:

  1. What do the chasquid logs say? That should help determine what the server is seeing.
  2. What is the error from the Python code?
  3. Can you re-run the smtp-check? The ip address of your server seems to have changed, so maybe it was a matter of DNS propagation?
   smtpObj = smtplib.SMTP() 
   smtpObj.connect(mail_host, 465)

You seem to confuse two ways to use TLS with client-server SMTP (aka Submission).

  1. Implicit TLS
    The connection is initially protected using TLS. This is what is used on the standard port 465.

  2. STARTTLS
    The connection is initially established in plaintext but after ESMTP negotiation TLS is activated using STARTTLS command. This is what is used on the standard port 587.

For 1, use smtplib.SMTP_SSL(). For 2, use smtplib.SMTP() and then call smtplib.starttls().

Your error is caused by an attempt to use plaintext SMTP on port with Implicit TLS. That is, server expects client to initiate TLS but it instead sends SMTP EHLO.

Note: Just using above is not sufficient to make connection secure (sigh Python sigh). https://stackoverflow.com/questions/33857698/sending-email-from-python-using-starttls

@hyahm, I'm going to close this for now as it's been 3 months and we need more information to understand better what's going on, as explained in the last two comments.

If you have more information, please reopen so we can follow up. Thanks!