18

I am using aws-ses for transactional mailing.
And the email address has this format:

noreply@domain_name.com

The problem is that when the users receive their emails, they see that the sender's name is "noreply" but I'd like to change it to something custom and more friendly.

Here's how SES is configured:

const { SESClient, SendEmailCommand } = require("@aws-sdk/client-ses");
const REGION = "us-west-2"; //e.g. "us-east-1"
// Create SES service object.
const sesClient = new SESClient({ region: REGION });

const prepare_params = (destination_address, subject, html_email_content) => {
  // Set the parameters
  const params = {
    Destination: {
      /* required */
      CcAddresses: [
        /* more items */
      ],
      ToAddresses: [
        destination_address, //RECEIVER_ADDRESS
        /* more To-email addresses */
      ],
    },
    Message: {
      /* required */
      Body: {
        /* required */
        Html: {
          Charset: "UTF-8",
          Data: html_email_content,
        },
        Text: {
          Charset: "UTF-8",
          Data: "TEXT_FORMAT_BODY",
        },
      },
      Subject: {
        Charset: "UTF-8",
        Data: subject,
      },
    },
    Source: "noreply@domain_name.com", // SENDER_ADDRESS
    ReplyToAddresses: [
      /* more items */
    ],
  };
  return params;
};
const sendEmail = async (destination_address, subject, html_email_content) => {
  const params = prepare_params(
    destination_address,
    subject,
    html_email_content
  );
  const data = await sesClient.send(new SendEmailCommand(params));
  return data;
};
exports.sendEmail = sendEmail;

Any idea how to solve this?

AG_HIHI
  • 1,705
  • 5
  • 27
  • 69

1 Answers1

33

try to change

Source: "noreply@domain_name.com", // SENDER_ADDRESS

to (edited)

Source: "Friendly Name <noreply@domain_name.com>", // SENDER_ADDRESS

if this it works let me know!

euTIMER
  • 681
  • 3
  • 12
  • The problem is that I want to pick a custom name and the custom name is basically the domain name but capitalized and whenever I try it (domain_name@domain_name.com), AWS wouldn't let it pass. – AG_HIHI Dec 21 '21 at 10:44
  • Okey then try change the line i told you and add this `Source: "Friendly Name ", // SENDER_ADDRESS` let me know if works! – euTIMER Dec 21 '21 at 10:54
  • 1
    If this not works maybe try without `" "` – euTIMER Dec 21 '21 at 11:03
  • That doesn't work it says: "error InvalidParameterValue: Local address contains control or whitespace" – AG_HIHI Dec 21 '21 at 11:33
  • 1
    Actually that worked I forgot to add < > around the email address. Thank you very much – AG_HIHI Dec 21 '21 at 11:45
  • Does this have UTF-8 support? I'm using non-standard characters for `SenderName` / Friendly name (think Cyrilic, or Latin with diacritics), and they're getting replaced with ae or just omitted. – FiddlingAway Dec 12 '22 at 09:38
  • 1
    @FiddlingAway yep you can. AWS docs say it needs to be in this format `=?charset?encoding?encoded-text?=`. So for example, we do this for our company name: `=?UTF-8?B??= ` and just plug that straight into the SendEmailRequest.source() field (if using the AWS v2 Java SDK). – wildcat12 May 09 '23 at 23:03
  • @wildcat12 Thanks, but I managed to solve it in the meantime, by doing this: https://stackoverflow.com/a/74810680/6133426 – FiddlingAway May 10 '23 at 10:26