python3 通过smtplib模块发送邮件
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import smtplib
import email.mime.multipart
import email.mime.text
def send_email(SMTP_host, from_addr, password, to_addrs, subject='', content=''):
"""
发送邮件
:param SMTP_host: smtp.163.com
:param from_addr: 发送地址:xxx@163.com
:param password: 密码: password
:param to_addrs: 发送给谁的邮箱: xxx@qq.com
:param subject: 邮件主题: test
:param content: 邮件内容: test
:return: None
"""
msg = email.mime.multipart.MIMEMultipart()
msg['from'] = from_addr
msg['to'] = to_addrs
msg['subject'] = subject
content = content
txt = email.mime.text.MIMEText(content)
msg.attach(txt)
smtp = smtplib.SMTP()
smtp.connect(SMTP_host, '25')
smtp.login(from_addr, password)
smtp.sendmail(from_addr, to_addrs, str(msg))
smtp.quit()
send_email('smtp.163.com', 'xxxx@163.com', 'password', 'to_addrs', 'subject', 'content')