Sending an automatic mail

Asked by At

I am creating the automatic mail system which I have to send the filtered excel values daily

I filtered the excel values using Pandas and stored that in status, while sending mail using python I got some error like this

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

Code:

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']='[email protected]'
msg['To']='[email protected]'
msg.set_content("Kindly Go-Through the below mail",status)
mail=smtplib.SMTP("smtp.gmail.com",587)


mail.login('[email protected]','123')

mail.send_message(msg)

mail.close()

I need to send that filtered values only

1 Answers

0
Valentino On

The error is from this line:

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

The error tells you that status is a pandas.Series. msg.set_content cannot handle it, you must convert the series into a string.
Try for example with

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

body is a concatenation of all the values in the series converted to a string (if they are already strings, you may omit the map function).