Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hyahm opened this issue Jan 6, 2020 · 3 comments
Closed
Assignees
Labels

Comments

@hyahm
Copy link

hyahm commented Jan 6, 2020

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: 无法发送邮件")
@albertito albertito self-assigned this Jan 10, 2020
@albertito
Copy link
Owner

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?

@foxcpp
Copy link

foxcpp commented Jan 14, 2020

   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

@albertito
Copy link
Owner

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants