阿里云使用第三方邮件服务
zhou 2018.08.01
阿里云默认封掉了25端口,导致很多要使用25端口的邮件服务用不了(可能是想让我们都用它的付费邮件服务么)。谷歌了几下,发现smtp.qq.com可用,587端口,前提是需要一个设置开户了“POP3/SMTP"服务的QQ邮箱。
代码如下:
#-* coding:utf-8 -*-
import smtplib
from email.mime.text import MIMEText
def sendmail(context):
sender = 'xxxxxxxx@qq.com' #有smtp服务授权的qq邮箱
receiver = 'xxxxx@163.com'
subject = '【页面状态码监控】_20180801-18:30'
smtpserver = 'smtp.qq.com'
innerhtml = ''
for url, _, location in context:
innerhtml += "<tr><td>%s</td><td>%s</td><td>%s</td></tr>" % (url, _, location)
msg = MIMEText(
'''<table align='left' style='border:1px solid #ccccc; width:600px;'><tr><th>URL</th><th>status</th><th>location</th></tr>%s</table>''' % innerhtml,
'html', 'utf-8')
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = receiver
smtp = smtplib.SMTP(smtpserver,587) #587端口
smtp.starttls()
smtp.login(sender, 'xxxxxxxx') #注意这里不是邮箱密码,是smtp服务授权码
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()
sendmail([('url','status','location')])