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?
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...