"""
python 发送邮件,用授权码
"""
import smtplib
from email.mime.text import MIMEText
def send():
"""
发送邮件
:return:
"""
try:
stmpserver163='smtp.163.com'
stmpport=25
frommail='geovindu@163.com'
code163='geovindu'
toemails=['463588883@qq.com','geovindu@jw28.com']
#创建邮件:
msg=MIMEText('<h3>hi, how are you. send mail<h3>','html','utf-8') #邮件内容
msg['Subject'] = 'ICT 公益培训 考试日期通知' #主题
msg['To']=','.join(toemails) #收件人
msg['From']=frommail #发送人
#STMP
stmp=smtplib.SMTP(stmpserver163,stmpport) #创建STMP
stmp.login(frommail,code163)
# 发送邮件,发送人,收邮件人,发送内容
stmp.sendmail(frommail,toemails,msg.as_string())
stmp.close()
print("email ok")
except Exception as ex:
print(ex)