-2

The code below is used to send emails to the persons registering on my website.

Currently, the only person receiving the emails is the person who registered, however I'd like an email address e.g. support@mysite.com to be put in cc of every email.

Does the code below allow that or would it require significant changes?

import { UserModel } from '../user/model';
import { IMessageClient } from '../professional/types';
import { Professional } from '../professional/model';

const charset = 'UTF-8';

function sendSESEmail(
    recipient_email: string,
    subject: string,
    body: string,
    cb: (messageId: string, err?: Error) => void,
) {
    const aws = require('aws-sdk');
    aws.config.region = process.env.AWS_SES_REGION;
    const sender = process.env.AWS_SES_SENDER;
    const recipient = recipient_email;
    const ses = new aws.SES();

    const params = {
        Source: sender,
        Destination: {
            ToAddresses: [recipient],
        },
        Message: {
            Subject: {
                Data: subject,
                Charset: charset,
            },
            Body: {
                Html: {
                    Data: body,
                    Charset: charset,
                },
            },
        },
    };

    ses.sendEmail(params, (error: any, data: any) => {
        if (error) cb(undefined, error);
        else cb(data.messageId);
    });
}

export default function sendEmail(
    recipient: string,
    subject: string,
    body: string,
    cb: (err?: Error) => void,
) {
    sendSESEmail(recipient, subject, body, (_, err?) => {
        cb(err);
    });
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Greg
  • 3,025
  • 13
  • 58
  • 106
  • 1
    What do you mean _"allow"_ it? How much change do you consider _"significant"_? Did you read the docs (or types) for the SDK to see what params you can pass? – jonrsharpe Oct 17 '22 at 20:08

1 Answers1

0

According to documentation, you only need to add CcAddresses

    Destination: {
        ToAddresses: [recipient],
        CcAddresses: ['support@mysite.com']
    },

or, if you prefer bcc

    Destination: {
        ToAddresses: [recipient],
        BccAddresses: ['support@mysite.com']
    },
Apostolos
  • 10,033
  • 5
  • 24
  • 39