forked from qiyeboy/SpiderBook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.3.py
28 lines (26 loc) · 897 Bytes
/
5.3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#coding:utf-8
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
import smtplib
def _format_addr(s):
name, addr = parseaddr(s)
return formataddr((Header(name, 'utf-8').encode(), addr))
#发件人地址
from_addr = '[email protected]'
#邮箱密码
password = 'pass'
#收件人地址
to_addr = '[email protected]'
#163网易邮箱服务器地址
smtp_server = 'smtp.163.com'
#设置邮件信息
msg = MIMEText('Python爬虫运行异常,异常信息为遇到HTTP 403', 'plain', 'utf-8')
msg['From'] = _format_addr('一号爬虫 <%s>' % from_addr)
msg['To'] = _format_addr('管理员 <%s>' % to_addr)
msg['Subject'] = Header('一号爬虫运行状态', 'utf-8').encode()
#发送邮件
server = smtplib.SMTP(smtp_server, 25)
server.login(from_addr, password)
server.sendmail(from_addr, [to_addr], msg.as_string())
server.quit()