503 error in SES with Lambda (.net6)

0

When I run the lambda (.net 6) code locally pointing to the SES host, it works. But, when I call the lambda function, it returns 503 error and don´t send the email.

Considerations:

  • The lambda function is under a vpc´s public subnet
  • I'm using the .NET MailKit package to send the emails:

public void Send(string to, string subject, string html, string from = null) { // create message var email = new MimeMessage(); email.From.Add(MailboxAddress.Parse(from ?? _appSettings.EmailFrom)); email.To.Add(MailboxAddress.Parse(to)); email.Subject = subject; email.Body = new TextPart(TextFormat.Html) { Text = html };

        // send email
        using var smtp = new SmtpClient();
        smtp.Connect(_appSettings.SmtpHost, _appSettings.SmtpPort, SecureSocketOptions.Auto);
        smtp.Authenticate(_appSettings.SmtpUser, _appSettings.SmtpPass);
        smtp.Send(email);
        smtp.Disconnect(true);
    }

I´m using the sandbox setting and both (sender and receiver) are verified. I have also created an policy like bellow and attached it to the lambda role:

} "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ses:SendEmail", "ses:SendRawEmail" ], "Resource": "*" } ] }

Could anyone help me with this issue please?

1 Answer
0

Hi,

The lambda logs can give more insight on the type of the error you are getting. If you are trying to send messages through SES from a Lambda code and the message is received by SES, then you should receive a message ID. If there is no message ID, this means that the messages has not been received by SES at all, and in that case, the lambda logs should give you more insight about the error you are encountering.

Hope this helps! Mo

profile picture
Mo
answered a year ago
  • Sadly, I only found the timeout on lambda logs. None further information... I added some application logs and I realized that the timeout occurs on the (smtp.Connect(_appSettings.SmtpHost, _appSettings.SmtpPort, SecureSocketOptions.Auto);) step.

    I have consulted cloudtrail but got nothing...

    I also added AdministratorAccess role to the lambda policy and nothing...

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