smtp是直接調(diào)用163郵箱的smtp服務(wù)器,需要在163郵箱中設(shè)置一下。outlook發(fā)送就是Python直接調(diào)用win32方式。調(diào)用程序outlook直接發(fā)送郵件。
import win32com.client as win32 import xlrd outlook = win32.Dispatch('outlook.application') mail = outlook.CreateItem(0) receivers = ['Yutao.A.Wang@alcatel-sbell.com.cn'] mail.To = receivers[0] mail.Subject ='test1' workbook = xlrd.open_workbook('E:\kpi excel\00_summary.xls') mySheet = workbook.sheet_by_index(0) nrows = mySheet.nrows content = [] for i in range(nrows): ss = mySheet.row_values(i) content.append(ss) print(content) Truecontent =str(content) mail.Body = Truecontent mail.Attachments.Add('E:\kpi excel\00_summary.xls') mail.Send()
smtp發(fā)送郵件
import smtplib from email.mime.text import MIMEText mail_host = 'smtp.163.com' mail_user = '18298268658' mail_pass = 'cat123' sender = '18298268658@163.com' receivers = ['619538553@qq.com'] message = MIMEText('content','plain','utf-8') message['Subject'] = 'title' message['From'] = sender message['To'] = receivers[0] try: smtpObj = smtplib.SMTP() smtpObj.connect(mail_host,25) smtpObj.login(mail_user,mail_pass) smtpObj.sendmail( sender,receivers,message.as_string()) smtpObj.quit() print('success') except smtplib.SMTPException as e: print('error',e)
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com