Issue with sending email through ses

37 views Asked by At

My function is supposed to take an email adress and send a prewritten email to said email address. The only problem is that I keep getting the email sent back to sender and marked as spam. Not sure what the issue is. Is the email getting sent back it’s spam or is it marked spam because the email failed to deliver? The message is as follows: screenshot

I am sending through my email as a verified identity and verified it through email but not through dkim. Our domain also has not finished dkim configuration either when I checked, is this the issue?

Here is my code, is there a problem with it ? I tried to write code to be able to catch the error but to no avail. Any suggestion is very appreciated.

def email_reminder(user, subject_line, days_since_login, ses_client):

        if days_since_login >= 60:
            beginning_email_lines = f"""
                                    Hello {user},
            
                                    We've noticed that you have not logged into your AWS account in {days_since_login} days. 
            
                                          Your account has been been locked out."""
            
        else:
            beginning_email_lines = f"""
                                    Hello {user},
            
                                    We've noticed that you have not logged into your AWS account in {days_since_login} days. 
            
                                              your account will be locked out in {60 - days_since_login} day(s)."""

        counter = 0
        # call ses email function to send email to users based days since their last login
        while counter < 2:
            try:
                ses_client.send_email(
                    Source=
    '[email protected]',
                    Destination={
                        'ToAddresses': [user]
                    },
                    Message={
                        'Subject': {
                            'Data': subject_line
                        },
                        'Body': {
                            'Text': {
                                'Data': f""" {beginning_email_lines}

  
                                """
                            }
                        }
                    }
                )
            except Exception as e:
                counter += 1
                if counter >= 2:
                    logger.error(f"could not send email to user {user}, retries exceeded")
                    raise Exception("could not send email to user")
                else:
                    logger.error(f"could not send mail to {user}, error : {e}, trying again")
                    pass
0

There are 0 answers