Brevo
Deliver transactional emails through Brevo email
medusa-plugin-brevo-email
Notifications plugin for Medusa ecommerce server that sends transactional emails via Brevo.
Features
- Uses the email templating features built into BREVO
- The plugin is in active development. If you have any feature requests, please open an issue.
- Create PDF invoices and credit notes and attach them to the email
- Send out upsell emails to customers that have recently placed an order with certain collections
- Send out automated abandoned cart emails to customers that have abandoned their cart (based on last updated date of cart)
- Support different languages base on countrycode or locale. (Need to add "locale or countryCode to cart context on frontend)
Configuration
Enable in your medusa-config.js file similar to other plugins:
More events? (work in progress within the plugin!) See here
Config example with multi language
1234567891011121314151617181920const plugins = [// ... other plugins{resolve: `medusa-plugin-brevo-email`,options: {api_key: process.env.BREVO_API_KEY,from_email: process.env.BREVO_FROM_EMAIL,from_name: process.env.BREVO_FROM_NAME,// Event templates with countryCode and locale supportevents: {order: {placed: {en: process.env.BREVO_ORDER_PLACED_EN || 3,vn: process.env.BREVO_ORDER_PLACED_VN || 11, // Vietnamese templatedefault: process.env.BREVO_ORDER_PLACED || 3, // Fallback if neither countryCode nor locale match},canceled: {en: process.env.BREVO_ORDER_CANCELED_EN || 6,vn: process.env.BREVO_ORDER_CANCELED_VN || 14, // Vietnamese template
1234567891011121314151617181920const plugins = [// ... other plugins{resolve: `medusa-plugin-brevo-email`,options: {api_key: process.env.BREVO_API_KEY,from_email: process.env.BREVO_FROM_EMAIL,from_name: process.env.BREVO_FROM_NAME,bcc: process.env.BREVO_BCC || null,contact_list: {enabled: process.env.BREVO_CONTACT_LIST_ENABLED || true,contact_list_id: process.env.BREVO_CONTACT_LIST_ID || 2},pdf: {enabled: process.env.BREVO_PDF_ENABLED || false,settings: {font: process.env.BREVO_PDF_FONT || 'Helvetica',// [{file: 'yourfont.ttf', name: 'yourfont'},{file: 'yourfont-bold.ttf', name: 'yourfontbold'}]
Templates
The plugin uses the BREVO template system for emails. For attachments the plugin relies on the pdfkit library.
In your JSON templates you can use several types (and variables):
- Copy to clipboard
image
for (local) images - Copy to clipboard
text
for simple words, (long) sentences, paragraphs and links - Copy to clipboard
moveDown
for moving the cursor down one line - Copy to clipboard
hr
for a horizontal line - Copy to clipboard
tableRow
for a table(-like) row - Copy to clipboard
itemLoop
for looping over items in an order - Copy to clipboard
itemLoopEnd
for ending the item loop
Example:
1234567891011121314151617181920[{"type": "image","image": "image.png","x": 100,"y": 100,"fit": [200, 50]},{"type": "text","text": "This is a text","size": 20},{"type": "moveDown","lines": 2},{"type": "hr"},
image
Images are stored in Copy to clipboard/src/images/
and can be used in the template like this:
1234567{"type": "image","image": "image.png","x": 100,"y": 100,"fit": [200, 50]}
Copy to clipboardfit
has multiple options, see here for more info.
Optional:
- Copy to clipboard
align
horizontally align the image, the possible values are Copy to clipboardleft
, Copy to clipboardcenter
, or Copy to clipboardright
- Copy to clipboard
valign
vertically align the image, the possible values are Copy to clipboardtop
, Copy to clipboardcenter
, or Copy to clipboardbottom
text
Text can be used for words, sentences, paragraphs and links.
1234{"type": "text","text": "This is a text"}
If you use Copy to clipboardmoveDown
correct you won't need to use Copy to clipboardx
and Copy to clipboardy
for the text.
Optional:
These options can be used to style the text or to position it.
- Copy to clipboard
x
the x position of the text - Copy to clipboard
y
the y position of the text - Copy to clipboard
font
the font of the text - Copy to clipboard
size
the font size of the text - Copy to clipboard
color
the color of the text (Hex codes Copy to clipboard#ff0000
) - Copy to clipboard
width
the width of the text - Copy to clipboard
align
the alignment of the text, the possible values are Copy to clipboardleft
, Copy to clipboardcenter
, Copy to clipboardright
, or Copy to clipboardjustify
.
For more styling options, see here for more info.
moveDown
This is used to move the cursor down one or more line(s).
1234{"type": "moveDown","lines": 1}
hr
This is used to draw a horizontal line.
123{"type": "hr"}
Optional:
- Copy to clipboard
color
the color of the line (Hex codes Copy to clipboard#ff0000
) - Copy to clipboard
width
the width of the line if you don't want it to be the full width of the page - Copy to clipboard
height
the height of the line element, including padding - Copy to clipboard
y
the y position of the line if you can not rely on the cursor (affected by Copy to clipboardmoveDown
)
tableRow
This is used to draw a table row.
12345678910111213{"type": "tableRow","columns": [{"text": "Column 1","width": 200},{"text": "Column 2","width": 150}]}
Optional:
You can use the same options as for Copy to clipboardtext
to style the text in the table row. If you want a special column styled, you can add the options to the column object.
1234## AcknowledgementThis plugin is originally based on medusa-plugin-postmark by Fullstack-nl.