Skip to content

Send emails from a service ​

To make a backend service send an email you can make use of the luna email service. Underthehood it will use AWS SES to actually send the email. Testing that emails are sent is possible in lower environments as long as the environment is set up correctly. See the notes below.

Sending a new email message steps ​

To send a new or even existing email make use of the email service and follow these steps

Publish a SNS message to the email-topic ​

Publish a message to the SNS topic: env-email - the ARN will look something like:

EMAIL_TOPIC_ARN: !Sub 'arn:aws:sns:${AWS::Region}:${AWS::AccountId}:${Environment}-email'

The message should contain the type of email that it is as the event and the payload should have all the details necessary to send the email. See the SendEmailPublishMessage type as well as some examples defined in the types.

For example your message will look something similar to this:

  event: "SEND_KUDOS_EMAIL",
  payload: {
    to: ["received@and.digital"],
    cc: [],
    bcc: [],
    from: "me@and.digital",
    subject: 'New Notification - Email - Subject',
    recipientsIds: [],
    data: {
      from: "name";
      footer: {
        from: {
          fullName: "fullname - of - sender";
          jobRole: "jobrole - of - sender";
          businessUnit: "bu - of - sender";
          email: "email - of - sender";
        };
      };
      to: "name";
      foo: "bar",
      foo1: "bar1"
    }
  }

Add a email handler to the email queue handler ​

Add the necessary handler, and types to the email queue handler in order to handle the new type of email. See and follow the existing emails as examples.

If it is an existing email - you don't need to add anything else.

Testing Emails in lower environments ​

To test sending emails in lower environments, your lower environment needs to be set up correctly, consider the following configurations.

Within the email queue handler, there is a check for all messages received.

if (!isProduction) params.to = [params.from];

This will change the destination of the email to be the sender - so you can preview the email in your email client (like gmail)

SMTP Credentials in SSM ​

The Email service uses SMTP credentails:

getParameter('email/smtp-username', true),
getParameter('email/smtp-password', true),

Ensure these are in SSM within AWS.

Email Address is a verified identity in SES ​

Inorder to receive emails from AWS SES, and ultimatly the luna email service - your email address needs to be in the verified identities within AWS SES.

To do this, reach out to a tech-lead and they will add you to that list. You will then receive a email with instructions from AWS to verify your email address.

Made with ❤️ by the Luna team