【Python】最佳Python代码片段,帮你实现工作自动化
2024-01-02 13:54:50
一、发送带附件的电子邮件
import smtplib, ssl
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
sender_email = 'sender@gmail.com'
password = 'xxxxxxxx'
receiver_address = 'receiver@gmail.com'
body = "This is a test Python email"
message = MIMEMultipart()
message["From"] = "sender@gmail.com"
message["To"] = "receiver@gmail.com"
message["Subject"] = "Python Mail"
message["Bcc"] = "receiver@gmail.com"
message.attach(MIMEText(body, "plain"))
filename = "excel.xlsx"
with open(filename, "rb") as attachment:
part = MIMEBase("application", "octet-stream")
part.set_payload(attachment.read
文章来源:https://blog.csdn.net/wjianwei666/article/details/135336645
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!