Dears
I have a Code Connect to Oracle DB, get query as Daraframe and send email to receiver that exist in a column
As I Test When I set test_reciver argument to an email address test_reciver Email received but when I set (email Receiver) to the column of data frame, Email not received
#send mail function
def send_email(subject,to,cc,body):
sender_email = 'test@test.com'
receivers = to
host = "bulkmail.test.com"
server = smtplib.SMTP(host)
msg = MIMEText(body)
msg['Subject'] = subject
msg['to'] = to
msg['cc'] = cc
server.sendmail(sender_email,to,msg.as_string())
server.quit()
query = "select * from sometable"
test_reciver = "myemail@test.com"
con = cx_Oracle.connect(user_db,password_db,dsn_tns,encoding="UTF-8", nencoding="UTF-8")
cc = 'emailcctest@test.com'
df = pd.read_sql_query(query,con, index_col=None).head(1)
df = df.reset_index()
for index, row in df.iterrows():
print(row['EMAIL'])
subject = 'please clarify your Workgroup in SDM '
to = row['EMAIL']
body = 'sample body'
send_email(subject, to, cc, body)
con.close()