# coding = utf -8
import smtplib
from email.mime.text import MIMEText
email_host = "smtp.qq.com"              #指定使用qq邮箱
email_user = "81972730@qq.com"          #发件人邮箱用户名
email_psd = "huepwqghientbhfe"          #发件人密码
receivers = "380475066@qq.com"          #接收邮件人
subject = "python SMTP邮件测试"         #邮件主题
message = MIMEText("python 邮件发送测试....","plain","utf-8")           #邮件内容
message["Subject"] = subject
message["From"]= email_user
message["To"] = receivers
try:
    smtpObj = smtplib.SMTP()                       #创建一个SMTP对象
    smtpObj.connect(email_host)                    #通过connect方法链接到smtp主机
    smtpObj.starttls()                             #启动安全传输模式
    smtpObj.login(email_user,email_psd)            # 登录qq邮箱 校验用户,密码
    smtpObj.sendmail(email_user,receivers,message.as_string())     #发送邮件
    print("邮件发送成功")
except smtplib.SMTPException:
    print("ERROR:无法发送邮件")