Search code examples
c#amazon-web-servicesasp.net-coreamazon-ses

Amazon SES error: The From ARN is not a valid SES identity


I am new to amazone SES and trying to set up my .net core API to send emails using SES. Here is code I`m using to send emails:

SendEmailRequest request = new SendEmailRequest();
        request.FromEmailAddress = "email@outlook.com";//verified
        //request.
        Destination destination= new Destination();
        destination.ToAddresses = new List<string> {"some verified email"};
        request.Destination = destination;
        EmailContent content = new EmailContent();
        
        content.Simple = new Message
        {
            Body = new Body
            {
                Html = new Content
                {
                    Data = $@"<html>
                    //here is some code
                    </html>"
                }
            },
            Subject = new  Content{
                Data = "some subject"
            }
        };
        request.Content = content;
        request.FromEmailAddressIdentityArn = senderArn;
        var status = await _sesClient.SendEmailAsync(request); 

This code gives me such error: The From ARN <arn:aws:ses:eu-central-1:xxxxxxxxxxxxxx> is not a valid SES identity. On AWS console emails are verified: screenshot from console

Any ideas what I`m doing wrong?


Solution

  • Here is .NET Code that does work. The sender has to be verified in SES. See https://docs.aws.amazon.com/ses/latest/dg/creating-identities.html.

    public async void SendMessage(string text, string toAddress)
    {
           var sesClient = new AmazonSimpleEmailServiceClient(RegionEndpoint.USWest2);
           var sender = "scmacdon@amazon.com";
           var emailList = new List<string>();
           emailList.Add(toAddress);
    
           var destination = new Destination
                {
                    ToAddresses = emailList
                };
    
                var content = new Content
                {
                    Data = text
                };
    
                var sub = new Content
                {
                    Data = "Amazon Rekognition Report"
                };
    
                var body = new Body
                {
                    Text = content
                };
    
                var message = new Message
                {
                    Subject = sub,
                    Body = body
                };
    
                var request = new SendEmailRequest
                {
                    Message = message,
                    Destination = destination,
                    Source = sender
                };
    
                try
                {
                    await sesClient.SendEmailAsync(request);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
    

    Update Make sure you are using this version.

    enter image description here