-
Notifications
You must be signed in to change notification settings - Fork 9
Send In Blue Transactional
This module is used to send transactional emails, and to manage those templates.
- /app/lib/send-in-blue-transactional
import { SibGetTemplateId, SibDeleteSmtpTemplate, SibSendTransacEmail } from '../send-in-blue-transactional'
- fileNameRoot is like 'jest-test' which refers to the file
/assets/email-templates/jest-test.html
- returns a number which is the template id to be passed in subsequent api calls. If a template by the name repo-name/fileNameRoot is found, that template id is returned.
A comparison of the HTML file is made with what is already there and error messages are logged about differences, but the call is a success. It may be that the template is later updated on the Sendinblue side by someone who is not a developer. This is fine. But the error messages will serve as a reminder that those updates should be brought back to the repo and checked in.
If a template is not found, then the html file by that name from /assets/email-templates is uploaded and the id is returned.
props is an object of the properties to be passed to SendInBlue in the api call. See Send a Transactional Email for more details. The minimum is
{ to: [{email: you@yours.com, name: 'You Yours'}],
templateId: 6,
params: {...}
}
- returns message id, a string like
<[email protected]>
- templateId - the id of an existing template
Templates are placed in /assets/email-templates
Templates are html files, with {{ param }}
that are replaced by data when the message is sent.
Using Visual Studio Code html files can be edited in split window mode, where the html is edited as text in one window, and viewed in another. Install the HTML Preview extension. After you open the HTML file, ctrl+k v or cmd+k v
will open the preview window.
Templates can also be created on Sendinblue using there editor, and then exported into html which can be saved into a file in /assets/email-templates.
It is this system of using the repo name and file root name that makes it possible to manage template ids over time and repos and projects. Avoid creating a template in Sendinblue and then hardcoding the template Id.
Two Environment Variables need to be set in the .bashrc file:
export SENDINBLUE_API_KEY='xkeysib-axxxxxxxxxx'
export SENDINBLUE_DEFAULT_FROM_EMAIL='[email protected]'
The environment variables must be set for these tests to run. Otherwise they will be skipped without error. This testing has side effects:
- The
jest-test
template will be created in the SENDINBLUE account, with this repo name prepended. - If there was already an
undebate-ssp/jest-test
template there, it will be deleted and a new one will be added. - The Sendinblue templateId will always be incremented. (when a template is deleted, it's template id can never be reused)
- An email will be sent to the SENDINBLUE_DEFAULT_FROM_EMAIL that should be manually checked.
npm run test app/lib/__tests__/send-in-blue-transactional.js
Go to Sendinblue.com to setup an account. This slide deck walks though signing up on Sendinblue and getting the SENDINBLUE_API_KEY. Developers can do this for testing using a personal email, without charge. Send In Blue Account Sign Up