import smtplib |
from email.mime.text import MIMEText |
msg = MIMEText( '这是一封测试邮件' ) |
msg[ 'Subject' ] = '测试邮件' |
msg[ 'From' ] = 'sender@example.com' |
msg[ 'To' ] = 'recipient@example.com' |
smtp_server = 'smtp.example.com' |
smtp_port = 587 |
smtp_username = 'sender@example.com' |
smtp_password = 'password' |
with smtplib.SMTP(smtp_server, smtp_port) as smtp: |
smtp.starttls() # 启用TLS加密 |
smtp.login(smtp_username, smtp_password) |
smtp.send_message(msg) |