一、发送带附件的电子邮件
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