1 import smtplib
2 import email.mime.multipart
3 import email.mime.text
4
5 def send_email(content=''):
6 """
7 发送邮件
8 :param SMTP_host: smtp.163.com
9 :param from_addr: 发送地址:xxx@163.com
10 :param password: 密码: password
11 :param to_addrs: 发送给谁的邮箱: xxx@qq.com
12 :param subject: 邮件主题: test
13 :param content: 邮件内容: test
14 :return: None
15 """
16
17 # 发送邮箱smtp服务器地址
18 SMTP_host = 'smtp.163.com'
19 # 发送邮箱账户
20 from_addr = '#######@163.com'
21 # 发送邮箱账户密码
22 password = '********'
23 # 收件人邮箱地址
24 to_addrs = '##########@139.com'
25 #右键主题
26 subject = '关于爬虫报警'
27
28 msg = email.mime.multipart.MIMEMultipart()
29 msg['from'] = from_addr
30 msg['to'] = to_addrs
31 msg['subject'] = subject
32 content = content+'\n状态异常'
33 txt = email.mime.text.MIMEText(content)
34 msg.attach(txt)
35
36 smtp = smtplib.SMTP()
37 smtp.connect(SMTP_host, '25')
38 smtp.login(from_addr, password)
39 smtp.sendmail(from_addr, to_addrs, str(msg))
40 smtp.quit()
41
42 send_email()