0

我正在运行 Rasbian Buster 并使用 Msmtp 从命令行发送电子邮件,它工作得很好。

当我尝试使用 Python 发送电子邮件时,它惨遭失败,我尝试了来自网络的各种 python 示例,例如

# Sending Email Alerts via Zoho
#
#
import smtplib

server = smtplib.SMTP_SSL('smtp.zoho.com',port=465) #server for sending the email

server.ehlo() # simple starting of the connection
server.login('test_email@zoho.com','pwd_12345') # login credentials and password

msg = """From:test_email@zoho.com
Subject: Test Email \n
To: recipient_email@gmail.com \n"""
# This is where the email content goes. It could be information about the error, time of day, where in the script, etc.

server.sendmail('test_email@zoho.com','recipient_email@gmail.com',msg) # this is where the email is sent to the recipient

server.quit() # exit the connection

...但不幸的是,我总是收到以下错误:

Traceback (most recent call last):
  File "/usr/lib/python3.7/smtplib.py", line 387, in getreply
    line = self.file.readline(_MAXLINE + 1)
  File "/usr/lib/python3.7/socket.py", line 589, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/test_email_python_06.py", line 6, in <module>
    server = smtplib.SMTP('smtpauths.bluewin.ch',port=465) #server for sending the email
  File "/usr/lib/python3.7/smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python3.7/smtplib.py", line 338, in connect
    (code, msg) = self.getreply()
  File "/usr/lib/python3.7/smtplib.py", line 391, in getreply
    + str(e))
smtplib.SMTPServerDisconnected: Connection unexpectedly closed: [Errno 104] Connection reset by peer

作为新手,任何提示将不胜感激。

谢谢!

4

1 回答 1

0

This issue has been solved!

My ISP uses SSL on port 465 and my command line email client MSMTP works just great using that.

As I was so desperate, so that I startet to play around and just use port 25 and "Bingo" the sending of emails works now just fine, the funny part is that my ISP suggest to use port 465.

于 2019-08-14T07:54:48.453 回答