Python messages that send HTML content

Source: Internet
Author: User

1 #messages that send HTML content2 Importsmtplib, time, OS3  fromEmail.mime.textImportMimetext4  fromEmail.headerImportHeader5 6 7 defsend_mail_html (file):8     " "Sending HTML content messages" "9     #Send MailboxTenSender ='[email protected]' One     #Receive Mailbox AReceiver ='[email protected]' -     #Send Message subject -t = time.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ()) theSubject ='Automated Test Results _'+T -     #Send Mailbox Server -SmtpServer ='192.168.20.190' -     #Send email user/password +Username ='Zhangkai' -Password ='123456' +  A     #Read HTML file contents atf = open (file,'RB') -Mail_body =F.read () - f.close () -  -     #Assemble message content and title, Chinese required parameter ' utf-8 ', single byte character not required -msg = Mimetext (Mail_body, _subtype='HTML', _charset='Utf-8') inmsg['Subject'] = Header (subject,'Utf-8') -msg[' from'] =Sender tomsg[' to'] =receiver +     #sign in and send mail -     Try: theSMTP =Smtplib. SMTP () * Smtp.connect (smtpserver) $ smtp.login (username, password)Panax Notoginseng Smtp.sendmail (sender, receiver, msg.as_string ()) -     except: the         Print("message failed to send! ") +     Else: A         Print("message sent successfully! ") the     finally: + smtp.quit () -  $  $ defFind_new_file (dir): -     " "find the latest files in the directory" " -File_lists =Os.listdir (dir) theFile_lists.sort (key=LambdaFn:os.path.getmtime (dir +"\\"+fn) -                     if  notOs.path.isdir (dir +"\\"+fn)Wuyi                     Else0) the     #print (' latest file: ' + file_lists[-1]) -File = Os.path.join (dir, file_lists[-1]) Wu     Print('full file path:', file) -     returnfile About  $  -DIR ='D:\\test_data\\auto_test_result'  #Specify the file directory -File = Find_new_file (dir)#find the latest HTML file -send_mail_html (file)#Sending HTML content messages

Python messages that send HTML content

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.