python 自动邮件发送 报错smtplib.SMTPServerDisconnected: Connection unexpectedly closed
import smtplib from email.mime.text import MIMEText from email.message import EmailMessage #email = EmailMessage() ## Creating a object for EmailMessage #email['from'] = 'xyz name' ## Person who is sending #email['to'] = 'xyz id' ## Whom we are sending #email['subject'] = 'xyz subject' ## Subject of email #email.set_content("Xyz content of email") ## content of email #with smtplib.SMTP(host='smtp.qq.com',port=465)as smtp: ## sending request to server # smtp.ehlo() ## server object #smtp.starttls() ## used to send data between server and client #smtp.login("email_id","Password") ## login id and password of gmail #smtp.send_message(email) ## Sending email #print("email send") ## Printing success message sender = '1165707116@qq.com' receivers = '1173760256@qq.com' msg = MIMEText('hi im hrz') msg['Subject'] = 'Test mail' msg['From'] = '573434343@qq.com' msg['To'] = '117376024@qq.com' with smtplib.SMTP_SSL('smtp.qq.com') as server: server.login('573434343@qq.com','*******') server.sendmail(sender, receivers, msg.as_string()) print("mail successfully sent")
把
smtplib.SMTP 改成
smtplib.SMTP_SSL('smtp.qq.com')问题得到解决
本文来自博客园,作者:蚌壳里夜有多长,转载请注明原文链接:https://www.cnblogs.com/dbahrz/p/17654351.html
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 2 本地部署DeepSeek模型构建本地知识库+联网搜索详细步骤