python - 无法发送多封电子邮件,因为我被中止(断开连接)
问题描述
使用 smtplib(python 3.6)发送多封电子邮件时出现“中止(断开连接)”,我在网上找不到太多信息。我很确定错误来自服务器而不是我的代码,但我想知道如何解决这个问题,或者至少知道如何通过谷歌获取更多信息,因为我对自己的情况一无所知要解决这个问题。
这是我正在使用发送一封电子邮件的函数:(我调用了这个函数五次,我得到了错误)。
import smtplib
def enviar_um_mail(to, subject, body):
#source: https://stackabuse.com/how-to-send-emails-with-gmail-using-python/
user = '<mail here>'
password = '<passwrd here>'
sent_from = user
to = 'somemail@somedomain.org'
email_text = 'text of e-mail here'
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(user, password)
server.sendmail(sent_from, to, email_text)
server.close()
print ('Email sent!')
except Exception as e:
print ('Something went wrong...')
print(e)
当调用此函数五次时,python shell 显示:
Email sent!
Email sent!
Email sent!
Email sent!
Email sent!aborted (disconnected)
解决方案
推荐阅读
- networking - Python 中的 TCP Traceroute - 卡住了
- haskell - 实现类型类函数时无法匹配类型错误
- gcloud - 谷歌云笔记本实例运行脚本不在启动中
- python - Pandas:使用嵌入逗号读取 csv
- c# - C# xml 反序列化不会将子元素提取到列表中
- r - 使用数据框列表的公共列创建数据框 - R
- javascript - 找不到问题是快递服务器问题
- debugging - 如何在 rust 中编写“非断言”调试代码
- java - jUnit 测试抛出 NullPointerException
- django - 为什么我会收到 pymongo ServerSelectionTimeoutError?