【Python】最佳Python代码片段,帮你实现工作自动化

发布时间:2024年01月02日

一、发送带附件的电子邮件

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
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。