Why I Built the SES Easy Mailer Node Module
Chiheb Nabil
Posted on February 1, 2024
As a software developer, I often find myself in situations where I need to send emails from my applications.
Whether it's for sending notifications, password resets, or promotional content, email is a crucial part of many web applications.
Amazon's Simple Email Service (SES) is a reliable and scalable solution for sending emails, but it can be a bit complex to use directly. That's why I decided to build the SES Easy Mailer Node module.
Making Email Sending Easier with SES
The SES Easy Mailer module simplifies the process of sending emails using Amazon SES.
It provides a simple and easy-to-use interface for sending emails, abstracting away the complexities of the underlying SES APIs.
This makes it a great choice for developers who want to leverage the power of Amazon SES without having to deal with its intricacies.
Here's a simple example of how to send an email with SES Easy
const { createTransporter, sendMail } = require('ses-easy-mailer');
const { SESClient } = require('@aws-sdk/client-ses');
const client = new SESClient(
region: "us-east-1",
credentials: {
accessKeyId: "",
secretAccessKey: "",
}
);
const transporter = createTransporter(client);
Using Local Html Template
const from = 'sender@example.com';
const to = 'recipient@example.com';
const subject = 'Hello, world!';
const templateType = 'file';
const templatePath = './template.html';
const templateData = { name: 'John Doe' };
const attachments = [];
await sendMail(
transporter,
from,
subject,
templateType,
templatePath,
templateData,
attachments,
to
)
Using SES Template
On the other hand, if you prefer to use SES's built-in template system, SES Easy Mailer has got you covered.
You can create and manage your templates directly in SES and simply reference them by name when sending emails. This is a great option for developers who want to manage their templates separately from their code.
Here's an example of how to send an email using an SES template:
const templateType = 'ses';
const templateName = 'se-template-name'; // The name of the template you created in SES
await sendMail(
transporter,
from,
subject,
templateType,
templateName,
templateData,
attachments,
to
)
Simplifying Attachments and Templating
Adding attachments to your emails is as simple as passing an array of objects, each representing an attachment.
The module takes care of the rest, ensuring that your attachments are correctly included in the sent email.
Here's an example of how to send an email with attachments :
let buffer = Buffer.from("hello world!", "utf-8");
let attachments = [
{
filename: "test.txt",
content: buffer,
encoding: "base64",
}
]
Conclusion
Building the SES Easy Mailer Node module has been a fun and rewarding experience. It's always great to build something that not only solves your own problems but can also be useful to other developers. If you're looking for a simple and easy-to-use solution for sending emails with Amazon SES, I encourage you to give SES Easy Mailer a try !
Posted on February 1, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.