python邮件脚本

#coding=utf8
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr

# 发送方邮箱地址
sender = ''
# 发送方邮箱授权码
sender_pwd = ''
# 接收方邮箱地址
receiver = ''
# SMTP地址
smtp_add = 'smtp.exmail.qq.com'
# SMTP端口
smtp_port = '465'

def mail():
    ret = True
    mail_msg = "Python邮件发送测试"
    msg = MIMEText(mail_msg, 'html', 'utf-8')
    msg['From'] = formataddr(["发送方别名", sender])
    msg['To'] = formataddr(["接收方别名", receiver])
    msg['Subject'] = '主题-测试邮件'
    server = smtplib.SMTP_SSL(smtp_add, smtp_port)
    server.login(sender, sender_pwd)
    server.sendmail(sender, [receiver, ], msg.as_string())
    server.quit()
    ret=False

    return ret
    ret = mail()
    if ret:
        print("邮件发送成功")
    else:
        print("邮件发送失败")
mail()