news 2026/6/23 10:08:34

Python 批量发送邮件

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Python 批量发送邮件

批量发送邮件

import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import ssl import time smtp_server = "example.test.com" port = 587# For starttls (consider using 587) sender_email = "example@test.com" password = "xxx" # WARNING: SSL verification is being DISABLED below. # This is INSECURE and should only be used for local testing. context = ssl._create_unverified_context() print("WARNING: SSL certificate verification is DISABLED (INSECURE).") try: server = smtplib.SMTP(smtp_server, port) server.ehlo() # 可以省略 # Start TLS using an unverified (insecure) context server.starttls(context=context) # INSECURE: certificate not verified server.ehlo() # 可以省略 server.login(sender_email, password) print("登录成功") # Create the email message message = MIMEMultipart("alternative") message["Subject"] = "测试主题" message["From"] = sender_email # message["To"] = "example@test.com" text = "test" html = """ <html> <body> <p>test<br> test! </p> </body> </html> """ part1 = MIMEText(text, "plain") part2 = MIMEText(html, "html") message.attach(part1) message.attach(part2) # Send the email to multiple recipients with a small delay recipients = ["example@test.com", "example@test.com"] for recipient in recipients: message["To"] = recipient try: server.sendmail(sender_email, recipient, message.as_string()) print(f"邮件已发送至: {recipient}") time.sleep(2) # 适当的时间间隔 except Exception as e: print(f"发送邮件到 {recipient} 时出错: {e}") except Exception as e: print(f"错误: {e}") finally: # 仅在连接仍然存在时调用 quit() try: if 'server' in locals() and getattr(server, 'sock', None): server.quit() except Exception: pass

发送附件邮件

from email.mime.base import MIMEBase from email import encoders message = MIMEMultipart() message["From"] = sender_email message["To"] = "receiver@example.com" message["Subject"] = "带附件的邮件" body = "这是一个带附件的邮件" message.attach(MIMEText(body, "plain")) filename = "document.pdf" with open(filename, "rb") as attachment: part = MIMEBase("application", "octet-stream") part.set_payload(attachment.read()) encoders.encode_base64(part) part.add_header( "Content-Disposition", f"attachment; filename= {filename}", ) message.attach(part)
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/22 22:51:29

vrep/coppeliasim与MATLAB联合仿真机械臂抓取 机器人建模仿真

vrep/coppeliasim与MATLAB联合仿真机械臂抓取 机器人建模仿真 运动学动力学直线圆弧笛卡尔空间轨迹规划&#xff0c;多项式函数关节空间轨迹规划 ur5协作机器人抓取/机械臂流水线搬运码垛最近在折腾UR5协作机器人抓取仿真&#xff0c;发现用V-REP&#xff08;现在叫CoppeliaSim…

作者头像 李华
网站建设 2026/6/17 16:19:38

notepad--多行编辑终极指南:解锁批量处理的高效密码

notepad--多行编辑终极指南&#xff1a;解锁批量处理的高效密码 【免费下载链接】notepad-- 一个支持windows/linux/mac的文本编辑器&#xff0c;目标是做中国人自己的编辑器&#xff0c;来自中国。 项目地址: https://gitcode.com/GitHub_Trending/no/notepad-- 还在为…

作者头像 李华
网站建设 2026/6/22 23:05:35

Wan2.2-T2V-A14B如何生成带有红绿灯切换的交通指挥动画?

如何用 Wan2.2-T2V-A14B 生成红绿灯切换的交通动画&#xff1f;&#x1f916;&#x1f6a6; 你有没有试过&#xff0c;只写一段话&#xff0c;就能“召唤”出一个活生生的城市十字路口&#xff1f; 车流缓缓停下&#xff0c;红灯亮起&#xff1b;几秒后黄灯闪烁&#xff0c;绿灯…

作者头像 李华
网站建设 2026/6/20 9:57:39

终极指南:使用Crypto-JS快速实现前端数据安全加密

在现代Web开发中&#xff0c;前端数据安全已成为不可忽视的重要环节。Crypto-JS加密库作为一款强大的JavaScript加密工具&#xff0c;为开发者提供了完整的加密解决方案。本文将通过实际演示&#xff0c;带你3分钟掌握AES加密配置&#xff0c;并深入解析HMAC签名最佳实践。 【免…

作者头像 李华
网站建设 2026/6/21 2:07:52

3分钟搞定Kafka测试:kcat模拟集群终极指南

3分钟搞定Kafka测试&#xff1a;kcat模拟集群终极指南 【免费下载链接】kcat Generic command line non-JVM Apache Kafka producer and consumer 项目地址: https://gitcode.com/gh_mirrors/kc/kcat 还在为搭建Kafka测试环境而烦恼吗&#xff1f;kcat命令行工具为你提供…

作者头像 李华