import smtplib
from email.mime.text import MIMEText
from email.header import Header

# 邮件内容设置
message = MIMEText('这是邮件正文内容', 'plain', 'utf-8')
message['From'] = Header("发件人名称", 'utf-8')
message['To'] = Header("收件人名称", 'utf-8')
message['Subject'] = Header("邮件主题", 'utf-8')

# SMTP服务器配置
smtp_server = "smtp.qiye.aliyun.com"
smtp_port = 465
username = "verify@swordsman.top"
password = "cha667389cha"

try:
    # 建立SSL连接并发送邮件
    smtp = smtplib.SMTP_SSL(smtp_server, smtp_port)
    smtp.login(username, password)
    # 使用有效的邮箱地址替换不存在的邮箱地址
    smtp.sendmail(username, ["shen@imikufans.cn"], message.as_string())
    print("邮件发送成功")
except Exception as e:
    print(f"邮件发送失败: {e}")
finally:
    smtp.quit()