从Excel或CSV文件中读取收件人列表,并自动发送电子邮件。
import smtplib
import pandas as pd
from email.mime.text import MIMEText
data = pd.read_csv('recipients.csv')
for index, row in data.iterrows():
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login('youremail@gmail.com', 'password')
message = MIMEText('This is a test email')
message['Subject'] = 'Test Email'
message['From'] = 'youremail@gmail.com'
message['To'] = row['email']
server.sendmail('youremail@gmail.com', [row['email']], message.as_string())
server.quit()