Python 官方文档:入门教程 => 点击学习
python发送邮件报SSLError Background 做自动化发送邮件提醒功能时发现无法连接smtp.office365.com服务器,报ssl版本错误。 > `ssl.SSLError: [
做自动化发送邮件提醒功能时发现无法连接smtp.office365.com服务器,报ssl版本错误。
> `ssl.SSLError: [SSL: WRONG_VERSioN_NUMBER] wrong version number(_ssl.c:1129)`
这是一个 Python 中的 SSL 错误,通常表示请求的 SSL 版本不受支持。这通常是因为该服务器支持的 SSL 版本与客户端请求的版本不匹配。如果遇到此错误,可以通过以下几种方法解决:
查阅Microsoft邮件客户端配置信息:
IMAP 服务器名称outlook.office365.com
IMAP 端口 993
IMAP 加密方法TLS
POP 服务器名称outlook.office365.com
POP 端口 995
POP 加密方法 TLS
SMTP 服务器名称smtp.office365.com
SMTP 端口 587
SMTP 加密方法 STARTTLS
s = smtplib.SMTP_SSL("smtp.office365.com", timeout=30, port=587)
s = smtplib.SMTP("smtp.office365.com", timeout=30, port=587)s.starttls()
import smtplibfrom email.mime.multipart import MIMEMultipartfrom email.mime.text import MIMETextif __name__ == '__main__': msg_from = 'example@example.com' # 发送方邮箱 passwd = '*****' # 就是上面的授权码 to = ['example1@example1.com'] # 接受方邮箱 # 设置邮件内容 # MIMEMultipart类可以放任何内容 msg = MIMEMultipart() conntent = "这是一封由python自动发送的邮件" # 把内容加进去 msg.attach(MIMEText(conntent, 'plain', 'utf-8')) # 设置邮件主题 msg['Subject'] = "这个是邮件主题" # 发送方信息 msg['From'] = msg_from # 开始发送 # 通过SSL方式发送,服务器地址和端口 s = smtplib.SMTP("smtp.office365.com", timeout=30, port=587) # 登录邮箱 s.starttls() s.login(msg_from, passwd) # 开始发送 s.sendmail(msg_from, to, msg.as_string()) s.close() print("邮件发送成功")
来源地址:https://blog.csdn.net/WANGYUE9779/article/details/128835995
--结束END--
本文标题: Python发送邮件报错:ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1129)
本文链接: https://www.lsjlt.com/news/393778.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0