class UrlUtil: _profile = env.EnvConfig.profile project_dir = os.path.abspath( __file__)[0:os.path.abspath(__file__).find("\\util")] image_dir_self = "reports\\images" + DateUtil.get_date_to_day() image_dir = project_dir + "\\" + image_dir_self case_dir_self = "cases" case_dir = project_dir + "\\" + case_dir_self report_dir_self = "reports" report_dir = project_dir + "\\" + report_dir_self report_file_self = "reports\\report" + DateUtil.get_date_to_day() + ".html" report_file = project_dir + "\\" + report_file_self log_dir_self = "logs\\" + DateUtil.get_date_to_day() log_dir = project_dir + "\\" + log_dir_self config_file_self = "config\\application.xml" config_file = project_dir + "\\" + config_file_self if _profile == "trunk": _static_base_url = "http://core-stag-trunk.cbdmnc.com/admin" elif _profile == "dev": _static_base_url = "http://core-stag-rc.cbdmnc.com:8080/admin/" @staticmethod def get_login_page_url(): return UrlUtil._static_base_url + "login.html" @staticmethod def get_index_page_url(): return UrlUtil._static_base_url + "index.html"
def send_mail(): EmailUtil.mail.attach(MIMEText( '通过报告路径直接访问: xxxx\\TestReport\\Automation\\report\\report' + DateUtil.get_date_to_day() + '.html', 'plain', 'utf-8')) # 构造附件 att = MIMEBase('application', 'octet-stream') fp = open(UrlUtil.report_file, 'r', encoding="utf-8") att.set_payload(fp.read()) fp.close() encoders.encode_base64(att) att.add_header('Content-Disposition', 'attachment;filename="{0}"'.format(UrlUtil.report_file_self)) EmailUtil.mail.attach(att) server = smtplib.SMTP(host=EmailUtil.host) server.connect(EmailUtil.host, 25) server.ehlo() server.starttls() server.login(EmailUtil.username, EmailUtil.password) server.sendmail(EmailUtil.mail['From'], EmailUtil.mail['To'], EmailUtil.mail.as_string()) server.quit() server.close()