Vercel and Mailtrap Integration
Send Emails with Vercel and Mailtrap
Step-by-step guide on how to integrate Mailtrap with your application hosted on Vercel.
Mailtrap is an email-sending solution for developer and product teams. Focused on fast delivery and high inboxing rates for transactional and promo emails. Provides highly customizable API and 24/7 tech support.
Prerequisites:
- Vercel account with a project for which you’ll add your Mailtrap API key.
- If you haven’t set up your sending domain already, you’ll need to do it before we start—it takes ~5 minutes, and you can use our step-by-step article as a guide.
Step 1. Create your Mailtrap API token
In your Mailtrap dashboard, click on Settings → API Tokens. There, you should be able to see all active tokens, their creators, and access level.

To create an API key, click on Add Token in the upper-right corner and assign admin permissions so you can send emails with it.

Hit Save and then store your API key safely since you won’t be able to see it again. For more information, you can read our guide on Mailtrap API Tokens.
Step 2. Add your key to Vercel
Open your Vercel dashboard and go to the Settings for the project you want to add Mailtrap to:

Then, in the Environment Variables section of Settings, find the Key section and add MAILTRAP_API_TOKEN and your actual token, and click Save.

Important:
- If you want to quickly switch between sending and sandbox, you can also use the other variables, such as
MAILTRAP_USE_SANDBOXorMAILTRAP_INBOX_ID. - Since Vercel environment variables only become available after you redeploy your project, make sure to either push a new commit or click Deploy again in the Vercel dashboard.
Step 3. Reference the key in your code
Finally, make sure to reference the Mailtrap API key in your code so that your app/project can reference it when making requests.
For example, here’s what it would look like in Mailtrap’s official Node.js SDK configuration:
import { MailtrapClient } from "mailtrap";
const mailtrap = new MailtrapClient({
token: process.env.MAILTRAP_API_KEY, // your API key here https://mailtrap.io/api-tokens
});
mailtrap
.send({
from: { name: "Mailtrap Test", email: "sender@example.com" },
to: [{ email: "recipient@example.com" }],
subject: "Hello from Mailtrap Node.js",
text: "Plain text body",
})
.then(console.log)
.catch(console.error);