6

I am sending Emails via the aws-sdk for Nodejs like this:

const params = {
    Destination: {
        ToAddresses: [... ],
    },
    Message: {
        Body: {
            Html: {
                Data: `...`,
                Charset: 'utf-8'
            },
        },
        Subject: {
            Data: `...`,
            Charset: 'utf-8'
        }
    },
    Source: 'support@mydomain.com',
    ReturnPath: 'support@mydomain.com',
};
awsConfig.ses.sendEmail(params, (err, data))

The received email looks like this in Gmail: received email

However, I want to know how to change this name:

Currently the from name is support, because the from email is support@mydomain.com. But I want it to be replaced by the company like GitHub below.

Thanks in advance for any help!

Florian Ludewig
  • 4,338
  • 11
  • 71
  • 137
  • 3
    More often than not and API would be using a standardized library itself. So it's probably just `'Support Name '` just like it would be in the RAW mail format. – Neil Lunn Nov 25 '18 at 09:34
  • should I use the same value for `ReturnPath` ? – Florian Ludewig Nov 25 '18 at 09:37
  • I'm presuming so. It's the standard format for SMTP, so it "should" make sense that is what is basically in use since it's probably just passed through directly into the SMTP messages generated. Not sure if there's a documented source confirming that, but logic would dictate it's a pretty sound thing to test until it proves otherwise. – Neil Lunn Nov 25 '18 at 09:39
  • 1
    Yep. Documented. ALL RFC822 Compliant; https://docs.aws.amazon.com/ses/latest/DeveloperGuide/header-fields.html – Neil Lunn Nov 25 '18 at 09:47

2 Answers2

11

Here is what I ended up doing: I set the Source attribute in the params to

'CompanyName <support@mydomain.com>'

Thanks to @Neil Lunn

Florian Ludewig
  • 4,338
  • 11
  • 71
  • 137
  • And a big thank you to you for calling this out! I could not spot this in the AWS / SES documentation. Works perfectly. – KevinY Jan 23 '21 at 15:52
-1

You can use this syntax

// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region 
AWS.config.update({region: 'REGION'});

// Create sendEmail params 
var params = {
  Destination: { /* required */
    CcAddresses: [
      'EMAIL_ADDRESS',
      /* more items */
    ],
    ToAddresses: [
      'EMAIL_ADDRESS',
      /* more items */
    ]
  },
  Message: { /* required */
    Body: { /* required */
      Html: {
       Charset: "UTF-8",
       Data: "HTML_FORMAT_BODY"
      },
      Text: {
       Charset: "UTF-8",
       Data: "TEXT_FORMAT_BODY"
      }
     },
     Subject: {
      Charset: 'UTF-8',
      Data: 'Test email'
     }
    },
  Source: 'SENDER_EMAIL_ADDRESS', /* required */
  ReplyToAddresses: [
      'EMAIL_ADDRESS',
    /* more items */
  ],
};       

// Create the promise and SES service object
var sendPromise = new AWS.SES({apiVersion: '2010-12-01'}).sendEmail(params).promise();

// Handle promise's fulfilled/rejected states
sendPromise.then(
  function(data) {
    console.log(data.MessageId);
  }).catch(
    function(err) {
    console.error(err, err.stack);
  });