亲爱的们
我有一个代码连接到Oracle数据库,以Daraframe的身份获取查询,并将电子邮件发送给列中存在的接收者
当我将TEST_Reciver参数设置为电子邮件地址TEST_Reciver时进行测试,但当我将(Email Receiver)设置为数据框列时,未收到电子邮件
# 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()
1条答案
按热度按时间oknwwptz1#
通过使用Send_Message而不是Sendmail for smtplib将电子邮件作为对象发送可解决此问题