aws-sdk-jsaws-pinpoint

How to CC and BCC in AWS Pinpoint using NodeJS


I followed the instructions found here:

https://docs.aws.amazon.com/pinpoint/latest/developerguide/example_pinpoint_SendMessages_section.html

I am able to send emails, but CC and BCC aren't present.

I believe my issue is in this configuration right here (copied from the link above):

const params = {
  ApplicationId: projectId,
  MessageRequest: {
    Addresses: {
      Destination: {
        ToAddresses: toAddress,
        CcAddresses: ccAddresses,
        BccAddresses: bccAddresses,
      },

      [toAddress]: {
        ChannelType: "EMAIL",
      },
    },
    MessageConfiguration: {
      EmailMessage: {
        FromAddress: senderAddress,
        SimpleEmail: {
          Subject: {
            Charset: charset,
            Data: subject,
          },
          HtmlPart: {
            Charset: charset,
            Data: body_html,
          },
          TextPart: {
            Charset: charset,
            Data: body_text,
          },
        },
      },
    },
  },
};

This is the version that I have:

"@aws-sdk/client-pinpoint": "^3.183.0",

Any one got ideas on what I could be missing?


Solution

  • Ok, here is what I did to solve this. I couldn't find any example with 'client-pinpoint-EMAIL' so here is my own.

    1. use a different npm package... not 'client-pinpoint' but rather 'client-pinpoint-email'
    2. then use a different function and shape of input to get emails to cc and bcc.

    Min code example below:

    const { PinpointEmail } = require("@aws-sdk/client-pinpoint-email");
    const { SendEmailCommand } = require("@aws-sdk/client-pinpoint-email");
    
    
    const pinClient = new PinpointEmail({
      region: aws_region,
      credentials: credentials,
    });
    
    const senderAddress = "NameOfYourFirm <hello@yourcompany.com>"
    const toAddress = 'email_to_send_address@gmail.com'
    const ccEmails = ['email_to_cc@gmail.com']
    
    const params = {
          FeedbackForwardingEmailAddress: senderAddress,
          FromEmailAddress: senderAddress,
          ReplyToAddresses: [senderAddress],
          Destination: {
            ToAddresses: [toAddress],
            CcAddresses: ccEmails,
          },
          Content: {
            Simple: {
              Subject: {
                Charset: charset,
                Data: subject,
              },
              Body: {
                Html: {
                  Charset: charset,
                  Data: body_html,
                },
              },
            },
          },
        };
    
     try {
          const data = await pinClient.send(new SendEmailCommand(params));
          console.log("Email sent! Message ID: ", data["MessageId"]);
          return data; 
        } catch (err) {
          console.log("Error", err);
        }