Learn how to integrate Bolt.new AI with Mailgun in 2026 with this simple step-by-step guide for seamless email automation and smarter workflows.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
To integrate Bolt.new with Mailgun, you don’t “connect Bolt to Mailgun.” Instead, you write normal backend code (Node.js inside Bolt’s server files) that calls Mailgun’s REST API using your Mailgun API key and domain. You store secrets as environment variables in Bolt.new’s env panel. Then you expose a backend function or API route that your front‑end or AI agent can call to send actual emails. Bolt is just the workspace where you scaffold and run this integration.
The core idea is simple: Bolt.new runs your backend code, and that backend calls Mailgun’s REST API. You add your Mailgun API key + domain to environment variables, install the official Mailgun JS SDK (or use fetch), and create a backend endpoint that sends emails. This is the same way you’d integrate Mailgun anywhere else — Bolt just gives you a browser-based development environment.
1: Install Mailgun JS SDK in Bolt.new terminal:
npm install mailgun.js form-data
2: Add environment variables in Bolt.new’s Environment panel:
These are required because you cannot safely hardcode secrets in code.
3: In your backend code (e.g., server.js or an API route), wire Mailgun
// server.js (Bolt backend)
// Import deps
import express from "express";
import Mailgun from "mailgun.js";
import FormData from "form-data";
const app = express();
app.use(express.json());
// Initialize Mailgun client
const mailgun = new Mailgun(FormData);
const mg = mailgun.client({
username: "api",
key: process.env.MAILGUN_API_KEY // pulled from Bolt env
});
// Example route to send an email
app.post("/send-email", async (req, res) => {
try {
const { to, subject, text } = req.body;
const result = await mg.messages.create(process.env.MAILGUN_DOMAIN, {
from: "Your App <[email protected]>", // must match Mailgun domain rules
to,
subject,
text
});
res.json({ ok: true, result }); // success
} catch (err) {
res.status(500).json({ ok: false, error: err.message });
}
});
export default app;
4: Call this route from your front-end or from an AI function inside Bolt
// Example: calling the backend from front-end
async function sendEmail() {
const res = await fetch("/send-email", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
to: "[email protected]",
subject: "Hello from Bolt + Mailgun",
text: "This is a real email sent through Mailgun's API."
})
});
const data = await res.json();
console.log(data);
}
Bolt’s AI doesn’t directly “integrate” with Mailgun. Instead, it can:
The real integration is always just API calls running from your Bolt backend.
This is the correct, real, and production-valid way to integrate Mailgun with a Bolt.new project. You are simply building a backend in Bolt that talks to Mailgun’s REST API securely via environment variables.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.