【发布时间】:2021-12-06 09:31:48
【问题描述】:
我尝试使用下面的亚马逊 SES API 文档发送电子邮件,python 返回代码 250 表示正常,但我的电子邮件收到一条失败消息。谁能告诉我可能是什么问题?谢谢
蟒蛇:
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# https://us-east-2.console.aws.amazon.com/sesv2/home?region=us-east-2#/account
# https://console.aws.amazon.com/iam/home?#/s=SESHomeV4/us-east-2
mail_host = "email-smtp.us-east-2.amazonaws.com"
mail_user = "AKI....T7H"
mail_pass = "BHJ.....iS/x"
sender = 'thelou1s@...com'
receivers = 'thelou1s@...com'
msg = MIMEMultipart()
msg['From'] = sender
msg['To'] = receivers
msg['Subject'] = 'simple email in python'
message = 'here is the email'
msg.attach(MIMEText(message))
try:
print("try smtplib.SMTP")
smtp = smtplib.SMTP(mail_host, 587)
smtp.set_debuglevel(True)
print("try connect")
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
# smtpObj.connect(mail_host, 465)
print("try login")
smtp.login(mail_user, mail_pass)
print("try sendmail: " + msg.as_string())
smtp.sendmail(sender, receivers, msg.as_string())
print("Send Success")
smtp.close()
except smtplib.SMTPException:
print("Send Error")
log(retcode 250是代码端成功还是用户端成功?):
reply: retcode (250); Msg: b'Ok 010f017d8f0f1703-d018f2a9-833e-428e-9010-5e45818e51e4-000000'
data: (250, b'Ok 010f017d8f0f1703-d018f2a9-833e-428e-9010-5e45818e51e4-000000')
Send Success
来自亚马逊的电子邮件:
Delivery Status Notification (Failure)
An error occurred while trying to deliver the mail to the following recipients:
thelou1s@...com
here is the email
【问题讨论】:
-
您好像成功将邮件发送到服务器,但服务器无法投递给收件人。
-
当您收到
250 OK时,消息从aws 发出,他们已成功发送您的消息。现在取决于 recipeint 的服务器如何处理电子邮件。
标签: python smtp amazon amazon-ses