import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
sender_email = "no-reply@example.com"
receiver_email = "ss@163.com"
smtp_user = "" # SES SMTP 用户名(访问密钥 ID)
smtp_pass = "" # SES SMTP 密码(Secret Access Key)
msg = MIMEMultipart()
msg['From'] = sender_email
msg['To'] = receiver_email
msg['Subject'] = "Test Email"
body = "This is a test email from AWS SES."
msg.attach(MIMEText(body, 'plain'))
try:
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(smtp_user, smtp_pass) # 登录到 SMTP 服务器
text = msg.as_string()
server.sendmail(sender_email, receiver_email, text)
print("Email sent successfully.")
except Exception as e:
print(f"Error: {e}")
finally:
server.quit()