Tag Archives: PythonCentOS

[Solved] Python Error: CentOS failed to send mail without any error message

CentOS failed to send mail without any error message

A mail sending program written in Python runs successfully on the local computer windows10 and python 3.10.0, but fails to run on Alibaba cloud server CentOS 7.6 and python 3.6.8, and there is no error message (it may also timeout, but I am not patient to wait for the error result).

Solution:

Previous code:

1 #163 email
2 mail_host = 'smtp.163.com'
3 smtpObj = smtplib.SMTP()
4 smtpObj.connect(mail_host,25)
5 
6 # or
7 mail_host = 'smtp.163.com'
8 smtpObj = smtplib.SMTP(mail_host, 25)

After modification:

#163 email
mail_host = 'smtp.163.com'
smtpObj = smtplib.SMTP()
smtpObj.connect(mail_host,25)

or:

mail_host = 'smtp.163.com'
smtpObj = smtplib.SMTP_SSL(mail_host, 463)

Attachment: centos7 uses Python STMP to send mail without sending or error prompt