I have a scenario where I have Extract Emails from Database and send mails to the respective Users. The values fetched from the database can be of Single Email Id or Multiple Email Id.
I have written the following code and its throwing me an error when it encounters multiple email id seperated by comma.
for index, row in df1.iterrows():
myVar1 = row["abc"]
#myVar2 = row["Email"]
if row["Email"].count('@') > 1:
myVar2 = ','.join(row["Email"])
else:
myVar2 = row["Email"]
msg = email.message.Message()
msg['From'] = 'do.not.reply@xyz.com'
msg['To'] = myVar2
msg['Subject'] = "abc to be read - {0}".format(myVar1)
msg.add_header('Content-Type', 'text')
msg.set_payload("Hello Users,\n\n ABC - {0} has reached its limit.".format(myVar1))
smtp_obj = smtplib.SMTP("outlook.xyz.com")
smtp_obj.sendmail(msg['From'],msg['To'], msg.as_string())
smtp_obj.quit()
if it a single email id then the mail is trigerring properly but if multiple email is passed then each alphabet is seperated by comma
input 'abc@xyz.com,asd@xyz.com' error message : a,b,c,@,x,y,z,.,c,o,m,,,a,s,d,@,x,y,z,.,c,o,m
Please help me in this concern.
Thanks