1

My lambda environment is set up in us-east-2 however I know SES only is present in us-east-1. This is the code:

    sent_from = "[email protected]"
    send_to = "[email protected]"
    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

It times out right here with a 10 second time out. It always stops at this line of code: logger.info("send_emails: step 3: smtp") which means it stops here server.connect('email-smtp.us-east-1.amazonaws.com', 587).

I've given access to both of these email addresses in the SES AWS Console.

Do I have to move the function to us-east-1. Please keep in mind that my RDS instance is in us-east-2.

EDIT

These are my security group rules for outbound:

Outbound Port Rules

My Inbound rules are as follows:

Inbound Port Rules

The sources are my work and home machines.

4
  • from a quick read, are you sure you want to have this commented out? #server.ehlo() Commented Dec 26, 2019 at 19:45
  • Changing it and re-uploading the file now Commented Dec 26, 2019 at 19:49
  • No. It's still timing out. Commented Dec 26, 2019 at 20:01
  • how did you go , did you find the issue Commented Dec 27, 2019 at 6:36

1 Answer 1

1

The solution was to add the host name to the smtplib.SMTP() as well

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()

looks like its a python bug

Sign up to request clarification or add additional context in comments.

18 Comments

See above for my inbound and outbound rules. But I think my outbound rule is compliant with what you said. My RDS and lambda are in the same region us-east-2 but SES is only available in us-east-1. Will I have to set up peering between VPCs on each region for this Lambda? Will this be a problem?
No you don't need peering just to use ses, we have the same setup at my work.
updated the answer, this is working for me perfectly.
logger.info("send_emails: step 1: smtp") server = smtplib.SMTP('email-smtp.us-east-1.amazonaws.com') 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()
Still not working. Still timing out at the second line.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.