Why Lambda function does not send email

0

Hi

I am testing a lambda function that sends an email via SES. I created an IAM role with SES full access and attached it to function. I created an identity in SES for the source email and target email and verified both accounts. I created a domain because I was not sure if this is required or not to send emails out.

When I run the function it runs fine but I don't receive any emails in target email. I do get an email error for non delivery in the source email shown below.

When I click on cloudwatch logs, I do see this message even though it is not affecting the execution of function: Log group does not exist The specific log group: /aws/lambda/Test_sendemail does not exist in this account or region.

Do you know why I am not receiving any emails after I run the function?

import json
import boto3

def lambda_handler(event,context):
      client = boto3.client("ses")
      subject = "test subject from Lambda"
      body = "test body from Lambda"
      message = {"Subject": {"Data":subject}, "Body":{"Html":{"Data": body}}}
      response = client.send_email(Source = "test_01@yahoo.com",
                 Destination={"ToAddresses": ["test_02@yahoo.com"]}, Message = message)
      return response

An error occurred while trying to deliver the mail to the following recipients: test_02@yahoo.com

Test Event Name (unsaved) test event

Response { "MessageId": "010f018cf0b9aeb2-38c6a0e9-dd50-4aa0-bafe-82b83cf35a12-000000", "ResponseMetadata": { "RequestId": "76539bdd-42e7-40f3-a95f-adbda9db0b7f", "HTTPStatusCode": 200, "HTTPHeaders": { "date": "Wed, 10 Jan 2024 00:15:50 GMT", "content-type": "text/xml", "content-length": "326", "connection": "keep-alive", "x-amzn-requestid": "76539bdd-42e7-40f3-a95f-adbda9db0b7f" }, "RetryAttempts": 0 } }

Function Logs START RequestId: 42376609-f2cf-4f37-ae02-fe60712f3a33 Version: $LATEST END RequestId: 42376609-f2cf-4f37-ae02-fe60712f3a33 REPORT RequestId: 42376609-f2cf-4f37-ae02-fe60712f3a33 Duration: 1904.19 ms Billed Duration: 1905 ms Memory Size: 128 MB Max Memory Used: 72 MB Init Duration: 278.60 ms

1 Answer
2
Accepted Answer

Hello.

When I click on cloudwatch logs, I do see this message even though it is not affecting the execution of function: Log group does not exist The specific log group: /aws/lambda/Test_sendemail does not exist in this account or region.

The most likely reason why CloudWatch Logs cannot be found is that the IAM policy for outputting from Lambda to CloudWatch Logs is not set.
If you have not set up the IAM policy described in the document below, please try setting it up.
https://repost.aws/knowledge-center/lambda-cloudwatch-log-streams-error

Do you know why I am not receiving any emails after I run the function?

I sent an email using the same code in my environment and was able to confirm sending and receiving without any problems.
Did it go to your spam mail?

profile picture
EXPERT
answered 4 months ago
  • Hi

    I updated the IAM role attached to the Lambda function and added "CloudWatchFullAccess" AWS managed policy to it and I still get that cloudwatch log error. Could it be related to creating the function in "us-east-2" instead of "us-east-1"?

    <<<There is no emails sent to spam folder. I am getting this non-delivery email in source email. >>>

    I am surprised it is running fine at your end. Could it be related to my "Free Tier Account" or is there a way to know more details why AWS cannot deliver the email? Do you have to have a domain or something else configured for SES?

    thanks,

  • I updated the IAM role attached to the Lambda function and added "CloudWatchFullAccess" AWS managed policy to it and I still get that cloudwatch log error. Could it be related to creating the function in "us-east-2" instead of "us-east-1"?

    The region in which you create your Lambda function should not matter. If it is the default setting, I think the log will be output to the same region as the Lambda function.

    I am surprised it is running fine at your end. Could it be related to my "Free Tier Account" or is there a way to know more details why AWS cannot deliver the email? Do you have to have a domain or something else configured for SES?

    You can use SES even if you have a free account. Also, if the email address is verified, you can send, so there is no problem even if you do not configure the domain. When troubleshooting SES, I think you need to refer to the following documents and check them one by one. For example, the bounces listed in "Check for sending issues from Amazon SES to the recipient domain" are possible causes for not being able to send emails. https://repost.aws/knowledge-center/ses-unable-receive-email

  • Hi I am wondering if this email delivery problem might be due to "Yahoo" security blocking some auto message from AWS? Have you used Yahoo email addresses or Gmail or Corporate Email addresses in your test?

    https://repost.aws/questions/QUMl39S_9PSjCT6PQI6ow7fg/unable-to-deliver-to-yahoo-addresses-ses-ip-getting-blocked

    https://stackoverflow.com/questions/25378125/ses-delivery-status-notification-failure

    Do you think the CloudWatch Log would show what is causing the problem if it works or not?

    Thanks,

  • I do not use Yahoo email addresses. I did the test using Gmail. It is possible that Yahoo is blocking it, but in that case I don't think we can handle it.

    Do you think the CloudWatch Log would show what is causing the problem if it works or not?

    I think you can check the failure of SES API execution, but I don't think you can see the information that it is blocked on Yahoo etc.

  • Yes, it was Yahoo blocking Email. Worked fine using GMAIL addresses.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions