python两种发邮件的方式smtp和outlook 您所在的位置:网站首页 outlook的pop3 python两种发邮件的方式smtp和outlook

python两种发邮件的方式smtp和outlook

#python两种发邮件的方式smtp和outlook| 来源: 网络整理| 查看: 265

smtp是直接调用163邮箱的smtp服务器,需要在163邮箱中设置一下。outlook发送就是python直接调用win32方式

调用程序outlook直接发送邮件。

import win32com.client as win32import xlrdoutlook = win32.Dispatch('outlook.application')mail = outlook.CreateItem(0)receivers = ['[email protected]']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.nrowscontent = []for i in range(nrows): ss = mySheet.row_values(i) content.append(ss) print(content) Truecontent =str(content)mail.Body = Truecontentmail.Attachments.Add('E:\\kpi excel\\00_summary.xls')mail.Send()smtp发送邮件

import smtplibfrom email.mime.text import MIMETextmail_host = 'smtp.163.com'mail_user = '18298268658'mail_pass = 'cat123'sender = '[email protected]'receivers = ['[email protected]']message = MIMEText('content','plain','utf-8')message['Subject'] = 'title'message['From'] = sendermessage['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)



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有