After the message is generated html test report
Import smtplib, Time from email.mime.text Import MimeText from email.mime.multipart Import MimeMultipart # used to qq mail, the mailbox 163 transmits class the SendEmail (): DEF the __init__ (Self, file_name): self.file_name = file_name self.send_user = " 449258***@qq.com " # account to send mail self.password = " *** " # authorization code to send email rather than mail password self.email_host = " smtp.qq.com " #Qq transmission mail server address is 'smtp.qq.com', 136 mail is 'smtp.136.com' DEF the send_mail (Self, user_list, Sub, Content): # Create instance a belt attachment Message = MimeMultipart () message [ ' the From ' ] = self.send_user # sender message [ ' the To ' ] = " ; " .join (user_list) # recipient message [ ' the Subject ' ] = Sub # topic # message body content message.attach (MimeText (Content, ' Plain ' ,' UTF-. 8 ' )) # configured (Annex to the page in HTML format) now The time.strftime = ( " % Y-D-%%% H_ M-% of M_% S " , time.localtime (the time.time ( ))) ATT = MimeText (Open (self.file_name, ' RB ' ) .read (), ' HTML ' , ' UTF-. 8 ' ) ATT [ " the Content-the Type " ] = ' file application / OCTET-Stream ' ATT [ " the Content-Disposition " ] = ' Attachment; filename = "% s_MyReport.html"'% Now message.attach (ATT) # transmit Server = smtplib.SMTP_SSL (self.email_host, 465 ) # server.set_debuglevel (. 1) # prints out all information and the SMTP server interaction server.login (self.send_user, self.password ) server.sendmail (self.send_user, user_list, message.as_string ()) server.quit () # close the connection DEF send_main (Self): # user_list = [ '[email protected]', '[email protected]' ] user_list = [ ' [email protected] ' ] # recipients collection Sub = " Interface automated test report " # topic = Content " Interface Automated Test results: See Annex " # text self.send_mail (user_list, sub, content)