# encoding=utf-8
import os
import time
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Header
import ConfigParser
class SendEmail(object):
def __init__(self, file_with_path):
config = ConfigParser.SafeConfigParser()
config.read('policy.ini')
self.file_with_path = file_with_path
self.file_name = os.path.basename(file_with_path)
self.sender = 'xuxw@2345.com'
self.receiver = [value for _, value in config.items('email')]
self.username = 'xuxw@2345.com'
self.password = 'xxw+1033'
def send(self):
msgRoot = MIMEMultipart('related')
str_today = time.strftime("%Y-%m-%d")
str_title = u'2345王牌浏览器升级测试报告' + str_today
msgRoot['Subject'] = str_title
msg = r'''<div><br></div><div><div style="font-family: 'lucida Grande', Verdana; line-height: normal;"><strong><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif; font-weight: normal;">大家好:</span></strong></div><div style="font-family: 'lucida Grande', Verdana; line-height: normal;"><div style="line-height: normal;"><strong style="text-indent: 32px;"><span lang="EN-US" style="font-size: 12pt; font-family: 微软雅黑, sans-serif; font-weight: normal;"> 2345</span></strong><strong style="text-indent: 32px;"><span style="font-size: 12pt; font-family: 微软雅黑, sans-serif; font-weight: normal;">王牌浏览器升级测试报告已自动生成,详见附件。本邮件为脚本自动发送,有疑问请联系徐小卫。</span></strong></div></div></div><div><sign signid="99"><div style="color:#909090;font-family:Arial Narrow;font-size:12px"><br><br><br><br>------------------</div><div style="font-size:14px;font-family:Verdana;color:#000;"><div style="overflow:hidden;"><div class="l_box" style="float:left;height:100px;margin:35px 10px 10px 0;padding:0 10px 0 15px;border-right:1px solid #dedede;"><div class="logo" style="height:35px;margin:35px 0 0 0;float:left;"><img src="https://exmail.qq.com/cgi-bin/viewfile?type=logo&domain=2345.com"></div></div><div class="c_detail" style="float:left;padding-top:35px;line-height:22px;color:#a0a0a0;zoom:1;"><h4 class="name" style="margin:0;font-size:14px;font-weight:bold;line-height:28px;color:#000;zoom:1;">徐小卫</h4><p class="position" style="margin:0;">高级测试工程师</p><p class="department" style="margin:0;">上海二三四五网络科技有限公司/软件研发中心/测试与质控部</p><p class="phone" style="margin:0;"></p><p class="addr" style="margin:0;line-height:22px;color:#a0a0a0;">上海浦东亮秀路112号Y2座9层</p></div></div></div></sign></div><div> </div><div><includetail><!--<![endif]--></includetail></div>'''
msgRoot["From"] = Header('徐小卫', 'utf-8')
msgText = MIMEText('%s' % msg, 'html', 'utf-8')
msgRoot.attach(msgText)
att = MIMEText(open(self.file_with_path, 'rb').read(), 'base64', 'utf-8')
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = ('attachment; filename="%s"' % self.file_name).encode("utf-8")
msgRoot.attach(att)
smtp = smtplib.SMTP()
smtp.connect('smtp.exmail.qq.com')
smtp.login(self.username, self.password)
smtp.sendmail(self.sender, self.receiver, msgRoot.as_string())
smtp.quit()
python发邮件
最新推荐文章于 2025-08-23 20:28:56 发布