import smtplib
from email.mime.text import MIMEText
mail_host = 'smtp.163.com'
mail_user = 'XXXXXX@163.com' # 发件人 账号
mail_pass = 'XXXXX' # TODO 该密码为认证密码 不是登录密码
mail_postfix = '163.com'
def send_mail(to_list,subject,content):
me = mail_user+"<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(content)
msg['Subject'] = subject
msg['From'] = me
msg['to'] = to_list
try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(me,to_list,msg.as_string())
s.close()
return True
except Exception as e:
print(str(e))
return False
send_mail('XXXXXX@qq.com', 'aaaa', 'aaa')