Skip to content

Email Service

Interface to send email notifications. In Stack9

  • Send Email
await services.email
  .send({
     from: { email: "test@test.com", name: "Stack9" }, // optional, if didn't specified, it will use the env environments
     to: [
       { email: "mail1@test.com", name: "Mail1" }
     ],
     templateId: "1234567899", // transactional template id
     dynamicTemplateData: {
       firstname: "Name",
       address: "St test",
       //... any data goes here
     }
  })
  .catch((error) => logger.error(error, "Error email"));
  • Check if the template id exists in SendGrid
try {
  await services.email.getTemplateById(templateIdToUse);
} catch (e) {
  logger.error(
    { SendGridTemplateId: templateIdToUse, Exception: e },
    'Send Grid Template {SendGridTemplateId} could not be found. {Exception}',
  );
}  

If running in a non production environment, the email service will check and filter allowed emails/domains in the property allowedAccountsForNonProdEmailSending defined in the app.json file.

More information about allowedAccountsForNonProdEmailSending in app-structures ⇗