Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/absalomedia/nodemailer-courier-transport
Nodemailer + Courier
https://github.com/absalomedia/nodemailer-courier-transport
courier-api nodemailer
Last synced: 27 days ago
JSON representation
Nodemailer + Courier
- Host: GitHub
- URL: https://github.com/absalomedia/nodemailer-courier-transport
- Owner: absalomedia
- License: mit
- Created: 2023-06-08T16:16:37.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-06-18T23:32:52.000Z (over 1 year ago)
- Last Synced: 2024-12-02T04:31:08.392Z (about 2 months ago)
- Topics: courier-api, nodemailer
- Language: JavaScript
- Homepage:
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nodemailer-courier-transport
## Setup
To set up the basic architecture so you can send Nodemailer emails via Courier, start with the following code
```js
const nodemailer = require("nodemailer");const courierTransport = require("nodemailer-courier-transport");
// This is your API key that you retrieve from courier.com account (free up to 10K monthly sends)
const auth = {
apiKey: "ABCDEFGHIJKLMN",
};const nodemailerCourier = nodemailer.createTransport(courierTransport(auth));
```Once this is set up, then you can set the various options available for your messaging and notifications using the SendMail function.
```js
nodemailerCourier.sendMail(
{
template: "courier-template-id", // Configured in Courier UI
brand_id: "courier-brand-id", // Configured in Courier UI
email: "[email protected]",
},(err, info) => {
if (err) {
console.log(`Error: ${err}`);
} else {
console.log(`Response: ${info}`);
}
});
```
## RecipientsThere are multiple ways to send outbound. You can chain multiple types together too, so potential exists to send the same message to a unique email, a unique user and a list at the same time.
- to an email
- to a user_id inside Courier
- to a list created inside Courier
- to a list pattern```js
nodemailerCourier.sendMail(
{
to: "courier-user-id", // Configured in Courier UI
list_id: "courier-list-id", // Configured in Courier UI
email: "[email protected]",
},
);
```## Dynamic data
Courier Notification that have dynamic data can be specified of the SendMail function. You need to pass the all the data types as a data object.```js
nodemailerCourier.sendMail(
{
email: "[email protected]",
data: {
name: "Recipient Name",
link:"https://www.courier.com/"
}
},
);
```## Template
Courier Notification templates can be set as part of the SendMail function. You should specify the unique template ID.```js
nodemailerCourier.sendMail(
{
template: "courier-template-id", // Configured in Courier UI
email: "[email protected]",
data: {
name: "Recipient Name",
link:"https://www.courier.com/"
}
},
);
```## Brand
Specifying a branded template design can be set as part of the SendMail function, referencing the Courier Notification brand ID. This will then be reflected across multiple templates being sent.```js
nodemailerCourier.sendMail(
{
brand: "courier-brand-id", // Configured in Courier UI
template: "courier-template-id", // Configured in Courier UI
email: "[email protected]",
data: {
name: "Recipient Name",
link:"https://www.courier.com/"
}
},
);
```## Overrides
The ability to override email base settings, whilst not having the fine grain control of provider based overrides, has been implemented.
These overrides cover:
- message subject
- message from - email
- message bcc - email
- message cc - email
- message reply_to - email```js
nodemailerCourier.sendMail(
{
template: "courier-template-id", // Configured in Courier UI
email: "[email protected]",
data: {
name: "Recipient Name",
link:"https://www.courier.com/"
}
},
override: {
from: "[email protected]",
reply_to: "[email protected]",
subject: "Overridden Subject",
bcc: "[email protected]",
cc: "[email protected]",
}
);
```## Email tracing
You can enable email tracing as part of the SendMail function, referencing the Courier Notification metadata tracing ID.```js
nodemailerCourier.sendMail(
{
template: "courier-template-id", // Configured in Courier UI
email: "[email protected]",
data: {
name: "Recipient Name",
link:"https://www.courier.com/"
}
},
trace: "your-custom-trace-id"
);
```## Timeouts
Message timeouts can be set as part of the SendMail function. It requires a number amount in seconds.```js
nodemailerCourier.sendMail(
{
template: "courier-template-id", // Configured in Courier UI
email: "[email protected]",
data: {
name: "Recipient Name",
link:"https://www.courier.com/"
}
},
timeout: 3600
);
```## Providers
You can send provider based overrides as an object to the SendMail function, allowing you to do domain specific variations as part of the messaging cycle.
As this is provider based overrides, please consult the Courier docs directly on this. This plugin aims to provide coverage for all the Courier messaging feature set, not replace it.
## Plugin development
There is a long term plan to move this to Typescript and use type validation using Zod to help gracefully manage input