from email.mime.text import MIMEText
from email.header import Header
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 = 'xxxxxxx'
to_addr = '[email protected]'
smtp_server = 'smtp.163.com'
msg = MIMEText('Python 爬虫运行异常,异常信息为遇到HTTP','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()
from email.header import Header
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 = 'xxxxxxx'
to_addr = '[email protected]'
smtp_server = 'smtp.163.com'
msg = MIMEText('Python 爬虫运行异常,异常信息为遇到HTTP','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()