Trouble using display name for AWS SES sender address

0

I'm working in .NET with the AWS SDK for Amazon SES mail. I'm trying to add a display name to the sender address like so:

using (var client = new AmazonSimpleEmailServiceClient(RegionEndpoint.USWest2))
{
    var sendRequest = new SendEmailRequest
    {
        Source = "My Website <noreply@mywebsite.com>"

Sometimes this works, but sometimes it throws an exception:

Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleException(IExecutionContext executionContext, HttpErrorResponseException exception) Local address contains control or whitespace.

When it fails, it seems as if it's trying to validate the display part as if it were the email address.

I know with the Amazon SES SMTP Interface I can set the sender address like so:

MailMessage message = new MailMessage();
message.From = new MailAddress("noreply@mywebsite.com", "My Website");

and the desired "My Website noreply@mywebsite.com" is achieved and works fine. But if I want to use the AWS SDK, I get this error intermittently. Has anyone else seen this or know what's going on? It seems as if the display name in AWS SDK may just not be supported.

1 Answer
1
Accepted Answer

If you want to specify the display name ('friendly name') that contains spaces, you should put that sender name in double quotes. Do not forget to escape them:

Source = "\"My Website\" <noreply@mywebsite.com>"

In general, always prefer that format.
Please refer to the Amazon SES Developer Guide. Please also refer to the RFC5322 standard.

profile pictureAWS
answered 2 years ago
  • This worked for me, though since it worked intermittently in the past, I can't fully test it. I didn't find anything in the documentation about surrounding the friendly name in quotes in case of whitespace, but since the quote marks don't show up literally in the email header when delivered, it makes sense that they would be acting to delimit the contents as a single string. We'll go with it. Thanks.

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