代码示例:
import smtplib
from email.mime.text import MIMEText
msg = MIMEText('This is a test email')
msg['Subject'] = 'Test Email'
msg['From'] = 'sender@example.com'
msg['To'] = 'recipient@example.com'
smtp_server = 'email-smtp.us-west-2.amazonaws.com'
smtp_port = 587
smtp_username = 'AWS_SES_SMTP_Username'
smtp_password = 'AWS_SES_SMTP_Password'
try:
with smtplib.SMTP(smtp_server, smtp_port) as smtp_server:
smtp_server.starttls()
smtp_server.login(smtp_username, smtp_password)
smtp_server.sendmail(msg['From'], msg['To'], msg.as_string())
print('Email sent successfully!')
except Exception as e:
print('Error sending email: {}'.format(str(e)))