发送自动mai

2024-06-16 11:35:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在创建自动邮件系统,我必须每天发送过滤后的excel值

我使用Pandas过滤excel值并将其存储在status中,当使用python发送邮件时,出现了如下错误

TypeError: sequence item 1: expected str instance, Series found

代码:

samples = pd.read_excel(excel_file,sheet_name=0)
status=samples.STATUS == "Need to Update"
msg=EmailMessage()
msg['Subject']='Limit Sample Management System'
msg['From']='abcd@gmail.com'
msg['To']='abcd@gmail.com'
msg.set_content("Kindly Go-Through the below mail",status)
mail=smtplib.SMTP("smtp.gmail.com",587)


mail.login('abcd@gmail.com','123')

mail.send_message(msg)

mail.close()

我只需要发送过滤后的值


Tags: compandasstatus错误邮件mailmsgitem
1条回答
网友
1楼 · 发布于 2024-06-16 11:35:11

错误来自此行:

msg.set_content("Kindly Go-Through the below mail",status)

这个错误告诉您statuspandas.Seriesmsg.set_content无法处理,必须将序列转换为字符串。
例如用

body = ' '.join(map(str, list(status))))
msg.set_content("Kindly Go-Through the below mail",body)

body是序列中转换为字符串的所有值的串联(如果它们已经是字符串,则可以省略map函数)。你知道吗

相关问题 更多 >