This article mainly describes the use of two kinds of Python e-mail SMTP and Outlook samples, with a certain reference value, interested in small partners can refer to.
SMTP is an SMTP server that calls 163 of mailboxes directly and needs to be set up in 163 mailboxes. The Outlook send is the Python call Win32 method directly. Callers Outlook sends messages directly.
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 Send mail
import smtplib from email.mime.text import mimetext mail_host = ' smtp.163.com ' mail_user = ' 182982 68658 ' 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 = SMTPL Ib. 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)