Why Brevo and Elysia JS Make the Perfect Pair for Streamlined Emailing
In today’s API-driven world, email functionality is essential. Whether you’re sending promotional emails, account verification, password…
In today’s API-driven world, email functionality is essential. Whether you’re sending promotional emails, account verification, password resets, or running email marketing campaigns, choosing the right email service provider can make or break your workflow.
For a long time, SendGrid was my go-to choice for email services, offering 100 free emails a month, competitive pricing, and relatively simple integration. However, when building an Elysia API, I decided to explore alternatives and discovered Brevo (formerly SendinBlue). Brevo provides some standout features, including:
- 300 free emails per day (a significant upgrade over SendGrid’s free tier).
- Automatic DNS configuration for seamless domain setup.
- Built-in email marketing tools, simplifying campaign management.
With these advantages, I decided to give Brevo a shot. Here’s how you can integrate Brevo with your Elysia JS backend (or any Node.js backend).
Step 1: Set Up a Brevo Email Template
- Log in to your Brevo dashboard.
- Navigate to Campaigns > Templates and click Create new template.
Brevo’s templates allow you to configure marketing or transactional email designs through a user-friendly dashboard. For dynamic placeholders, use the syntax {{params.name}}
to include variables like names or other custom data.
Step 2: Install the Brevo SDK
Add the Brevo SDK to your project:
bun add @getbrevo/brevo
Step 3: Add Your Brevo API Key
Set up your API key in an environment variable file:
BREVO_API_KEY=your-api-key-here
Step 4: Integrate Brevo with Elysia JS
Here’s how to integrate the Brevo SDK and send transactional emails:
import brevo from "@getbrevo/brevo";
const apiInstance = new brevo.TransactionalEmailsApi();
const apiKey = apiInstance.authentications["apiKey"];
apiKey.apiKey = process.env.BREVO_API_KEY as string;
export const sendPromotionEmail = async (email: string, name: string) => {
const sendSmtpEmail = new brevo.SendSmtpEmail(); // Create an email instance
sendSmtpEmail.templateId = 1; // Replace with your Brevo template ID
sendSmtpEmail.to = [{ email, name }]; // Set recipient details
sendSmtpEmail.params = { price: "$50.00" }; // Pass dynamic parameters
try {
await apiInstance.sendTransacEmail(sendSmtpEmail);
console.log("Brevo Promotion Email Sent: ", email);
} catch (error) {
console.error("Brevo Promotion Email Error: ", error);
}
};
What Makes Brevo a Great Choice?
- Generous Free Tier: 300 daily emails are more than enough for most small to medium-sized projects.
- Ease of Use: Brevo’s SDK and dashboard are straightforward, making integration quick and painless.
- Flexibility: Works seamlessly with Elysia JS and any Node.js backend.
- Scalable Features: From transactional emails to full-blown marketing campaigns, Brevo grows with your needs.
With Brevo integrated, your Elysia JS backend now has a robust email-sending capability, whether for transactional emails or large-scale campaigns. Give it a try and take your email functionality to the next level!
What’s your experience with email providers? Let me know in the comments!
Try BanKan Board — The Project Management App Made for Developers, by Developers
If you’re tired of complicated project management tools with story points, sprints, and endless processes, BanKan Board is here to simplify your workflow. Built with developers in mind, BanKan Board lets you manage your projects without the clutter.
Key Features:
- No complicated processes: Focus on what matters without the overhead of traditional project management systems.
- Claude AI Assistant: Get smart assistance to streamline your tasks and improve productivity.
- Free to Use: Start using it without any upfront cost.
- Premium Features: Upgrade to unlock advanced functionality tailored to your team’s needs.
Whether you’re building a side project, managing a team, or collaborating on open-source software, BanKan Board is designed to make your life easier. Try it today!