
def send_mail(send_mail):
# 发送邮箱服务器
smtp_server = 'smtp.163.com'
# 发送邮箱用户名密码
user = '15230831989@163.com'
password = 'OLSXOLCKOPJJWKFI'
# 接收邮箱
receives = ['1324176145@qq.com','3593882608@qq.com']
# 发送邮件和主题内容
subject = '爬取58司机发送邮件 【流程测试】'
content = '<html><h1 style="color:red">测试邮件发送</h1></html>'
# 构建发送与接收信息
msg_root = MIMEMultipart()
msg_root.attach(MIMEText(content, 'html', 'utf-8'))
msg_root['subject'] = subject
msg_root['From'] = user
msg_root['To'] = ','.join(receives)
# msg_root['To'] = '3593882608@qq.com'
# 构造附件3(附件为HTML格式的网页)
att3 = MIMEText(open(send_mail, 'rb').read(), 'base64', 'utf-8')
att3["Content-Type"] = 'application/octet-stream'
att3["Content-Disposition"] = 'attachment; filename='+send_mail.split('/')[-1]+''
msg_root.attach(att3)
# SSL协议端口号要使用465
smtp = smtplib.SMTP_SSL(smtp_server, 465)
# H E L O 向服务器标识用户身份
smtp.helo(smtp_server)
# 服务器返回结果确认
smtp.ehlo(smtp_server)
# 登录邮箱服务器用户名和密码
smtp.login(user, password)
print("Start send email...")
smtp.sendmail(user, receives, msg_root.as_string())
smtp.quit()
print("Send End!")