Question

I've got some .Net code I'm switching from the System.Net.MailMessage to Amazon SES and their .Net SDK v2. Is it possible to include a display name with SES using the SDK similar to the MailMessage object?

The relevant part of the old code looks something like this:

    MailMessage message = new MailMessage();
    MailAddress toAddress = new MailAddress(_user.Email, _user.DisplayName);
    message.To.Add(toAddress);

The relevant part of the new code (so far):

        SendEmailRequest request = new SendEmailRequest()
        {
            Source = _user.Email
        };
Was it helpful?

Solution

With the Java SDK you can include the display name in the sender field using the format:

John Doe <john.doe@example.com>

I assume it is the same with the .NET SDK.

OTHER TIPS

Just use the .ToString() method from the MailAddress object, and you'll get the John Doe <john.doe@example.com> string. Send this string to AWS.

You can set this in your App Settings or WebConfig and concatenate the name and email in your method like this:

var toAddress = $"{_configuration["AWS-SES:SenderName"]} <{_configuration["AWS-SES:SenderAddress"]}>";

its found for .NET

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top