我编写了一个脚本,可以将单独的电子邮件发送给 Excel 表中的所有联系人。该表如下所示:
Names Emails PDF
Name1 Email1@email.com PDF1.pdf
Name2 Email2@email.com PDF2.pdf
我到目前为止的代码如下:
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
from string import Template
import pandas as pd
e = pd.read_excel("Contacts.xlsx")
emails = e['Email'].values
PDF = e['PDF'].values
print(emails, PDF)
server = smtplib.SMTP(host='smtp.outlook.com', port=587)
server.starttls()
server.login('sender_email','sender_password')
msg = ("""
Hi there
Test message
Thankyou
""")
subject = "Send emails with attachment"
body = "Subject: {}\n\n{}".format(subject,msg)
for emails in emails:
server.sendmail('sender_email',emails,body)
print("Emails sent successfully")
server.quit()
问题:如何查找每个电子邮件地址(第 2 列)的正确附件(第 3 列)并使用 Python 将其附加到电子邮件中?