[英]smtlib not send email to email address from column list of pandas dataframe
親愛的
我有一個代碼連接到 Oracle DB,以 Daraframe 的形式獲取查詢並將 email 發送到列中存在的接收器
當我測試時,當我將 test_reciver 參數設置為 email 地址 test_reciver Email 收到但當我將(電子郵件接收者)設置為數據幀列時,沒有收到 Email
#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()
它通過發送 email 作為 object 與 send_message 而不是 sendmail 為 smtplib 解決
#send mail function
def send_email(subject,to,cc,body):
host = "bulkmail.test.com"
server = smtplib.SMTP(host)
msg = MIMEText(body)
msg['Subject'] = subject
msg['From'] = 'test@test.com'
msg['to'] = to
msg['cc'] = email_cc
serve.send_message(msg)
server.quit()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.