pip install python-decouple SMTP_HOST=smtp.example.com SMTP_PORT=587 SMTP_USERNAME=yourusername SMTP_PASSWORD=yourpassword python from decouple import config SMTP_HOST = config('SMTP_HOST') SMTP_PORT = config('SMTP_PORT', default=587, cast=int) SMTP_USERNAME = config('SMTP_USERNAME') SMTP_PASSWORD = config('SMTP_PASSWORD') python import smtplib from email.message import EmailMessage from settings import SMTP_HOST, SMTP_PORT, SMTP_USERNAME, SMTP_PASSWORD def send_email(subject, body, recipient): msg = EmailMessage() msg['Subject'] = subject msg['From'] = SMTP_USERNAME msg['To'] = recipient msg.set_content(body) with smtplib.SMTP(SMTP_HOST, SMTP_PORT) as smtp: smtp.login(SMTP_USERNAME, SMTP_PASSWORD) smtp.send_message(msg)


上一篇:
下一篇:
切换中文