1. Import the necessary packages first.

import smtplib

from email.mime.text import MIMEText

from email.MIMEMultipart import MIMEMultipart

import datetime

2. Define the mail sending function

def Send_Mail (Message): TODAY = datetime.date.today() CURRENTDAY= today.strfTime (‘ %Y-%m-%d ‘) MSG = MIMEMultipart() ‘ ‘att = MIMEText (open (r ‘D: \ report \ aa XLSX’, ‘rb’), read (), base64, Att [‘ content-type ‘] = ‘application/octet-stream’ att[‘ content-disposition ‘] = ‘attachment; MSG. Attach (att) “” content = STR (Message) # Body = imd_ebm.xlsx Attach (body) MSgto = ‘[email protected]’ # attach(body) msgto = ‘[email protected]’ Format [‘ [email protected] ‘; ‘[email protected]’] msgfrom = ‘[email protected]’ # return address, MSG [‘ subject ‘]= ‘Finish’ # MSG [‘ date ‘]=time.ctime() # time # MSG [‘ Cc ‘]= [email protected] [email protected] # mailpwd = ‘wangzijia1990’ # try: SMTP = smtplib.smtp () smtp.connect(r ‘smtp.qq.com ‘)# SMTP = smtp.connect(r ‘smtp.qq.com ‘)# smtp.login(mailuser, mailpwd) # Msgto, msg.as_string()) # send SMTP. Close () print “success mail” except Exception, e: print e,u” failure”