This article is based on Mailtrap's official tutorial on how to send email in Vercel.
Before we start
Required accounts
- Vercel account - to host your applications and manage environment variables
- Mailtrap account - to send emails with high deliverability rates
- Next.js project - to implement the email functionality
Prerequisites setup
- Verify your email sending domain - Mailtrap allows you to send emails only from a verified domain. Follow this guide to set up domain verification.
- Get your API token - Ensure your API Token has admin access level to your domain and email sending capabilities.
Step 1: Set up Mailtrap
Navigate to your Mailtrap dashboard and locate your API credentials:
- Click on Settings → API Tokens
- Review all active tokens, their creators, and access levels
- If you don't have an API key, click Add Token
- Assign the desired permissions (check API/SMTP permissions)
- Click Save and store your API key securely
Note that you won't be able to see the API key again after creation. For more detailed information, refer to the Mailtrap API Tokens guide.
Step 2: Create a Next.js function
Create a new API route in your Next.js application to handle email sending via Mailtrap: