mail.py 726 B

123456789101112131415161718192021222324
  1. import smtplib
  2. from email.mime.text import MIMEText
  3. # 设置邮箱信息
  4. smtp_server = 'smtp.gmail.com'
  5. smtp_port = 587
  6. sender_email = 'zooey@choozmo.com'
  7. sender_password = 'bnufmjzkyezputip'
  8. receiver_email = 'mia@choozmo.com'
  9. # 创建邮件内容
  10. subject = '註冊信'
  11. message = f"test"
  12. msg = MIMEText(message)
  13. msg['Subject'] = subject
  14. msg['From'] = sender_email
  15. msg['To'] = receiver_email
  16. # 连接到 SMTP 服务器并发送邮件
  17. with smtplib.SMTP(smtp_server, smtp_port) as server:
  18. server.starttls() # 开启 TLS 加密(如果需要)
  19. server.login(sender_email, sender_password)
  20. server.sendmail(sender_email, receiver_email, msg.as_string())
  21. print("Email sent successfully")