使用Python的AWS Lambda SES SMTPLib电子邮件超时

我的lambda环境已在us-east-2中设置,但是我知道SES仅存在于us-east-1中。这是代码:

    sent_from = "email1@gmail.com"
    send_to = "email2@gmail.com"
    aws_user_name = "<USER NAME KEY>"
    #stub - replace this
    aws_password = "<USER PASSWORD KEY>"
    logger.info("send_emails: start")

    for email in email_list:

        try:

            logger.info("send_emails: step 1: smtp")
            server = smtplib.SMTP()
            logger.info("send_emails: step 2: smtp")
            server.connect('email-smtp.us-east-1.amazonaws.com',587)
            #server.ehlo()
            logger.info("send_emails: step 3: smtp")            
            server.starttls()
            logger.info("send_emails: step 4: smtp")
            #logger.info("User: " + aws_user_user + " Password:" + aws_password)
            server.login(aws_user_name,aws_password)
            logger.info("Email Send To: " + email[1])
            logger.info("Test Point: send_emails: A")
            #server.sendmail(sent_from,email[1],email_body.as_string())
            #REPLACE THIS LINE.  THIS IS JUST FOR TESTING.
            server.sendmail(sent_from,send_to,email_body.as_string())
            server.close()
            insert_into_email_sent_tbl(email[0],"Success")
            logger.info('Email sent!')
            return True

        except Exception as e: 
            logger.info(e)  
            logger.info('Something went wrong...')
            insert_into_email_sent_tbl(email[0],"Fail")
            return False

在这里超时,超时10秒。它总是在以下代码行处停止:logger.info("send_emails: step 3: smtp"),这意味着它在此处server.connect('email-smtp.us-east-1.amazonaws.com',587)处停止。

我已在SES AWS控制台中访问了这两个电子邮件地址。

我是否必须将函数移至us-east-1。请记住,我的RDS实例位于us-east-2中。

编辑

这些是我的出站安全组规则:

使用Python的AWS Lambda SES SMTPLib电子邮件超时

我的入站规则如下:

使用Python的AWS Lambda SES SMTPLib电子邮件超时

来源是我的工作和家用机器。

fkdswfwqfet 回答:使用Python的AWS Lambda SES SMTPLib电子邮件超时

解决方案是将主机名也添加到smtplib.SMTP()

print("send_emails: step 1: smtp")
print("send_emails: step 1: smtp")
server = smtplib.SMTP('email-smtp.us-east-1.amazonaws.com')
print("send_emails: step 2: smtp")
server.connect('email-smtp.us-east-1.amazonaws.com',587)
#server.ehlo()
print("send_emails: step 3: smtp")            
server.starttls()

看起来像是蟒蛇bug

本文链接:https://www.f2er.com/2856636.html

大家都在问