打包后,希望测试组能及时收到相关包下载的信息,所以这里添加了发送邮件的功能。
SMTP是发送邮件的协议,Python内置对SMTP的支持,可以发送纯文本邮件、HTML邮件以及带附件的邮件。
由于这种便捷的关系,这里使用Python脚本实现整个过程。这里直接在网上搜索了相关知识,稍加修改有了下面的ipa.py 脚本内容:
# -*- coding: utf-8 -*-
from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.utils import parseaddr, formataddr
import smtplib
def _format_addr(s):
name, addr = parseaddr(s)
return formataddr(( \
Header(name, 'utf-8').encode(), \
addr.encode('utf-8') if isinstance(addr, unicode) else addr))
from_addr = '发送邮件的邮箱名'
password = '发送邮件的邮箱密码'
to_addr = '接收邮件的邮箱'
msg = MIMEMultipart()
#发送人名称
msg['From'] = _format_addr(u'客户端开发 <%s>' % from_addr)
msg['To'] = _format_addr(u'测试人员 <%s>' % to_addr)
#发送邮件主题
msg['Subject'] = Header(u'iOS日常包', 'utf-8').encode()
# add MIMEText:
msg.attach(MIMEText('包地址:fir.im.\n附件为fir下载二维码\n', 'plain', 'utf-8'))
# add file:
with open('/Users/charleswang/Downloads/fir.png', 'rb') as f:
mime = MIMEBase('image', 'png', filename='fir.png')
mime.add_header('Content-Disposition', 'attachment', filename='fir.png')
mime.add_header('Content-ID', '<0>')
mime.add_header('X-Attachment-Id', '0')
mime.set_payload(f.read())
encoders.encode_base64(mime)
msg.attach(mime)
server = smtplib.SMTP('smtp.exmail.qq.com', 25)
server.set_debuglevel(1)
server.login(from_addr, password)
server.sendmail(from_addr, [to_addr], msg.as_string())
server.quit()
备注:这里发送邮件需要在邮箱中进行设置,这里以QQ邮箱为例,点击设置->账户,下拉找到下图:
建立bulid_ipa.sh文件:
cd 工程根目录下
python /Volumes/Untitled/Chrome/ipapy-master/ipa.py
脚本运行结束提示:
reply: '250 Ok: queued as \r\n'
reply: retcode (250); Msg: Ok: queued as
data: (250, 'Ok: queued as')
send: 'quit\r\n'
reply: '221 Bye\r\n'
reply: retcode (221); Msg: Bye
至此,完成邮件发送