共計 956 個字符,預計需要花費 3 分鐘才能閱讀完成。
要批量發(fā)送郵件,可以使用 Python 的 smtplib 庫來實現(xiàn)。以下是一個簡單的示例代碼,演示如何使用 smtplib 庫批量發(fā)送郵件:
import smtplib
from email.mime.text import MIMEText
# 配置發(fā)件人信息
sender = 'sender@example.com'
password = 'password'
# 配置收件人列表
recipients = ['recipient1@example.com', 'recipient2@example.com']
# 配置郵件內容
subject = 'Test Email'
body = 'This is a test email.'
# 創(chuàng)建郵件對象
message = MIMEText(body, 'plain')
message['Subject'] = subject
message['From'] = sender
# 連接到 SMTP 服務器
smtp_server = 'smtp.example.com'
smtp_port = 587
smtp = smtplib.SMTP(smtp_server, smtp_port)
smtp.starttls()
smtp.login(sender, password)
# 發(fā)送郵件給每個收件人
for recipient in recipients:
message['To'] = recipient
smtp.sendmail(sender, recipient, message.as_string())
# 斷開與 SMTP 服務器的連接
smtp.quit()
在上述示例代碼中,需要配置發(fā)件人的郵箱地址和密碼、收件人列表、SMTP 服務器的地址和端口。然后創(chuàng)建郵件對象,設置郵件主題、內容和發(fā)件人信息。接下來,通過循環(huán)將郵件發(fā)送給每個收件人,并最后斷開與 SMTP 服務器的連接。
請注意,使用 smtplib 庫發(fā)送郵件需要配置發(fā)件人的郵箱地址和密碼,以便進行 SMTP 認證。另外,SMTP 服務器的地址和端口需要根據(jù)你使用的郵件服務提供商進行配置。
丸趣 TV 網 – 提供最優(yōu)質的資源集合!
正文完