Do not put in automatically sent on an automated test framework results to the mailbox function, in this article the mend, ha ha
1, on a code not introduced one by one in herein, this only describes the function code to send messages
2, create a public common sendmail.py file in the folder, send messages to store code
Import MimeText email.mime.text from
from email.header Import Header
Import smtplib
Import Time
Import OS
DEF the send_mail (file_new):
F = Open (file_new, 'RB')
mail_body reached, f.read = ()
f.close ()
username = '***' # outbox username (add your own email account)
password = '***' # outbox password
sender = '***' # sender's mailbox (add your own)
Receiver = [ '* ** ']
#receiver = [' *** '] # recipient mailbox
# The message body is MimeText
MSG = MimeText (mail_body,' HTML ',' UTF-. 8 ')
# mail object
msg [' subject '] = Header ( "automated test report", 'UTF-. 8'). encode ()
MSG [ 'the From'] = Header (U 'test lead <% s>'SENDER%)
MSG [ 'the To'] = Header (U 'technical lead <% s>'% sender)
MSG [ 'DATE'] = The time.strftime ( "% A,% B% D% the Y% H:% M:% S% Z")
SMTP = smtplib.SMTP ()
smtp.connect ( 'SMTP. exmail.qq.com ') # E-mail server (when I'm here with the QQ mailbox, other mailbox need to check in online at!)
smtp.login (username, password) # Log mail
smtp.sendmail (sender, receiver, msg. as_string ()) # sender and recipient
smtp.quit ()
Print ( "message sent! Note check.")
# here to return all files to HTML files in the folder and take a new HTML file
def new_file ( test_dir):
# test_dir lists all the files in the directory, results are returned in a list.
= os.listdir Lists (test_dir)
#Print (Lists)
file_path = os.path.join (test_dir, Lists [-1])
return file_path
more to send mail code will automatically find and send the latest HTML file to the mailbox .
3, the method is called a code entry, the incoming address sendmail file into the folder in operation
runner.run (Suite)
new_report_mail = new_file (r'D: \\ \\ the Result Event ')
log.info (new_report_mail)
send_mail (new_report_mail)
fp.close ()
4, I wrote the path to the folder absolute path , where you can modify their own under.
5, the above code is sent automatically run code that calls the entrance mail