forwardemail / email-templates

Create, preview (browser/iOS Simulator), and send custom email templates for Node.js. Made for @forwardemail, @ladjs, @cabinjs, @spamscanner, and @breejs.
https://forwardemail.net/docs/send-emails-with-node-js-javascript
MIT License
3.64k stars 339 forks source link

SourceArn and FromArn ignored #420

Closed ktwbc closed 3 years ago

ktwbc commented 3 years ago

Attempting to use the SES Transport with SourceArn/FromArn for cross-account usage. Using them in the new Email() object will not error but they are ignored.

   const email = new Email({
      message: {
        from: `Notification <notifications@example.com>`
      },
      send: true, // uncomment below to send emails in development/test env:
      juice: true, // pulls in linked CSS/JS into the body
      juiceResources: {
        preserveImportant: true,
        inlinePseudoElements: true,
        webResources: {
          images: 100,
          relativeTo: path.join(__dirname, 'emails'),
        }
      },
      transport: {
        SES: new SES({apiVersion: '2010-12-01'}),
        ses: {
          SourceArn: 'arn:aws:ses:us-east-1:1234567890:identity/notifications@example.com',
          FromArn: 'arn:aws:ses:us-east-1:1234567890:identity/notifications@example.com'
        }
      },

The email will show sending but because the SourceArn and FromArn are ignored, the email isn't actually sent. If I remove those lines and instead manually put them in the headers, such as:

    const headers = {
      'X-SES-SOURCE-ARN': 'arn:aws:ses:us-east-1:1234567890:identity/notifications@example.com',
       'X-SES-FROM-ARN': 'arn:aws:ses:us-east-1:1234567890:identity/notifications@example.com',
     };

  await email.send({
        template: 'sample-template',
        message: {
          to:  { name: 'John Doe', address: 'john.doe@example.com'} ,
          headers: headers,
        },
        locals: mergeFields
      });

Then the emails are sent and received correctly.

niftylettuce commented 3 years ago

This seems like a Nodemailer issue, not an issue with this package. Please file it over there.

niftylettuce commented 3 years ago

You should probably just put those default headers in. Which is documented here: https://github.com/forwardemail/email-templates#custom-default-message-options.

const email = new Email({
      message: {
        from: `Notification <notifications@example.com>`,
        headers: { ... } // <-- ADD THEM HERE
      },

// ...

cc @ktwbc