How to send automated emails from a Next.js app using a custom mail server

@sanjayjoshi Hi Mate

You can connect your own mail server (SMTP) to a Next.js app, but it’s usually not the best approach when you’re deploying on Vercel.

SMTP connections can be unreliable in serverless environments (timeouts, blocked ports, etc.), and you also have to deal with deliverability issues like SPF/DKIM setup yourself.

A much easier and more reliable option is to use a service like Resend. It’s designed specifically for apps running on Vercel and integrates really smoothly with Next.js.

Setup is very simple:

  • Install the SDK

  • Add your API key

  • Send emails via their API (no SMTP needed)

Example:

import { Resend } from 'resend';

const resend = new Resend(process.env.RESEND_API_KEY);

await resend.emails.send({
  from: 'onboarding@yourdomain.com',
  to: 'user@example.com',
  subject: 'Hello!',
  html: '<p>It works 🎉</p>',
});

So in short:
Yes, SMTP is possible, but using Resend (or a similar email API) is the recommended and more reliable approach on Vercel.