的方法有多种。以下是一种常见的方法:
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
sender_email = "your_email@example.com"
password = "your_email_password"
recipients = ["recipient1@example.com", "recipient2@example.com", "recipient3@example.com"]
message = MIMEMultipart()
message["Subject"] = "邮件主题"
message["From"] = sender_email
message["To"] = ", ".join(recipients)
message.attach(MIMEText("邮件正文", "plain"))
# 添加附件
# attachment = open("path_to_attachment_file", "rb")
# mime_attachment = MIMEBase("application", "octet-stream")
# mime_attachment.set_payload((attachment).read())
# encoders.encode_base64(mime_attachment)
# mime_attachment.add_header("Content-Disposition", "attachment; filename=attachment_filename")
# message.attach(mime_attachment)
with smtplib.SMTP("smtp.example.com", 587) as server:
server.starttls()
server.login(sender_email, password)
server.send_message(message)
请注意,上述代码中的"smtp.example.com"应替换为你的SMTP服务器地址,587应替换为你的SMTP服务器端口号。
这是一个基本的示例,你可以根据自己的需求进行修改和扩展。如果你想了解更多关于Python邮件发送的信息,可以参考腾讯云的邮件推送服务产品腾讯云邮件推送。
领取专属 10元无门槛券
手把手带您无忧上云