python 發郵件本地傳送沒問題 阿里雲Linix上傳送不出去問題
加上 smtplib.SMTP_SSL(mail_host, 465) #阿里雲把25埠封掉了
附完整程式碼
import pandas as pd import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import time
def get_current_time():
return str(time.strftime('%Y-%m-%d %H'))
current_time = get_current_time()
filename='/opt/user/jflm/liusonglei/stockEarlyWarning/data/stockEarlyWarning-20180525.xlsx' #附件地址
areceiver = '
if __name__ == '__main__': # mailto_list=['[email protected]','[email protected]'] data=pd.read_excel(filename, sheet_name=0) a=pd.DataFrame(data) b=a.iloc[:,0].size sub="萬達影票庫存" d='' #表格內容 for i in range(b): d=d+""" <tr> <td>""" + str(a.index[i]) + """</td> <td>""" + str(a.iloc[i][0]) + """</td> <td width="60" align="center">""" + str(a.iloc[i][1]) + """</td> </tr>""" html = """\ <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<body> <div id="container"> <p><strong>這是萬達影票"""+current_time+"""時的庫存:</strong></p> <div id="content"> <table width="30%" border="2" bordercolor="black" cellspacing="0" cellpadding="0"> <tr> <td width="40"><strong></strong></td> <td width="50"><strong>商品名</strong></td> <td width="60" align="center"><strong>庫存</strong></td> </tr>"""+d+""" </table> </div> </div> </div> </body> </html>
""" context = MIMEText(html,_subtype='html',_charset='utf-8') #解決亂碼 if send_mail(areceiver.split(',')+ acc.split(','),sub,context,filename): print ("傳送成功") else: print( "傳送失敗")