this example for everyone to share a specific code Python3 regular mail function, for your reference, the specific contents are as follows:

1,

 import OS import import module datetime # regularly sent, and the date of import shutil import smtplib # # file operation module from email.mime.text import MIMEText from message email.mime.multipart import MIMEMultipart from email.header import Header import time import xlwt #excel 

2, EXCEL

 to write def eWrite (fLocate, file_sheet, file_subject, style0): try: if os.path.exists (fLocate): os.remove (fLocate) # if the file exists, then delete the F = xlwt.Workbook (encoding='utf-8') # open excel file FS = f.add_sheet (file_sheet) #sheet subject (file_subjec = list T for I in) # list range (len (subject)): # find the date column 'in subject[i] if' date: col_num=i for I in range (len (subject) #sheet fs.write (0): title, I, subject[i]) for I in range (10): fs.col (I # cell width.Width=3333 print (WRITE) FINISHED) f.save (fLocate) except: Print (WRITE FAILED) 

3

 def eSend, email (sender, receiver, username, password, smtpserver, subject, e_content, file_path, file_name): try: = MIMEMultipart (message # headers) message['From'] = sender# send message['To'] = ".Join" (receiver) # collection message['Subject'] = Header (subject,'utf-8') message.attach (MIMEText (e_content,'plain','utf-8')) # mail text # Annex att1 (open = MIMEText structure (file_path+file_name,'rb') (.Read),'base64','utf-8') att1["Content-Type"] ='application/octet-stream' att1[] "Content-Disposition" = "attachment; filename=" +file_name message.attach (att1) SMTP = smtplib.SMTP (#) smtp.connect (smtpserver) # connection server smtp.login (username, password) # log smtp.sendmail (sender, receiver, message.as_string) (smtp.quit) (print) # send ("SEND") except: print ("SEND FAILED") 

4,

 while True: configuration and implementation of # configuration #__time_____ ehour=11# timing emin=49# timing esec=50# timing hours minutes seconds current_time = time.localtime (time.time) (date) # current time cur_time = time.strftime ('%H%M', time.lo (caltime) (time.time) str #__mysql_____ #__email_____) # current time sender = 'receiver = ['453032441@qq.com'] # # from email mailbox, multiple (list) mass username =' 'password =' # # sender name SMTP password, QQ is assigned a string to you, 163 is to set up their own smtpserver = '# mailbox server subject = "Hey here's something interesting" # headers ('i', e_content ='{0:^27}n{1:^27}n{2:^25}n{3:^25}'.format (-) /'re, '', '' (-)) # text = "D:/" #__file_____ file_path file_name= "shit.xls" # file location # file name fLocate = file_path + file_name # file path file_subject='I','MISS'.'U'#sheet file_sheet='ok' #sheet style0=xlwt.XFStyle title (style0.num_format_str='YYYY-MM-DD') if (# operation (current_time.tm_hour = = ehour) and (current_time.tm_min = = Emin) and (current_time.tm_sec = = ESEC)): Print (START) eWrite (fLocate, file_sheet, file_subject, style0) eSend (sender, receiver, username, password, smtpserver, subject, e_content, file_path, file_name (print) cur_time) time.sleep (1) 

all above is the

, I hope to help you study, also hope a lot of support script home.

This paper fixed link:http://www.script-home.com/python3-implements-the-timing-of-sending-mail-with-attachments.html | Script Home | +Copy Link

Article reprint please specify:Python3 implements the timing of sending mail with attachments | Script Home

You may also be interested in these articles!