首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法使用python发送电子邮件

无法使用python发送电子邮件
EN

Stack Overflow用户
提问于 2019-08-09 03:22:08
回答 1查看 1K关注 0票数 0

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

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

代码语言:javascript
运行
复制
# 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

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

代码语言:javascript
运行
复制
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

作为newbee,任何提示都将不胜感激。

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2019-08-14 15:54:48

这个问题已经解决了!

我的ISP在端口465上使用SSL,我的命令行电子邮件客户端MSMTP使用它工作得很好。

由于我是如此绝望,以至于我开始尝试使用25端口和"Bingo“发送电子邮件,有趣的是,我的ISP建议使用465端口。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57419382

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档