Kankei
Serverless

Enviar e-mails com Vercel Functions

Aprenda como enviar seu primeiro e-mail usando o Vercel Functions

Pré-requisitos

Para aproveitar este guia, você precisará:

1. Crie uma função Next.js

Crie um arquivo de rota em app/api/email/route.ts se estiver usando o App Router

const KANKEI_API_KEY = 'kankei_cFnbdF...';

export async function POST() {
  const response = await fetch('https://kankei.yotei.dev/api/email', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${KANKEI_API_KEY}`,
    },
    body: JSON.stringify({
      to: ['email-do-cliente@email.com'],
      subject: 'Olá mundo!',
      html: '<strong>Funcionou!</strong>',
    }),
  });

  if (response.ok) {
    const data = await response.json();
    return Response.json(data);
  }
}

2. Testar localmente

Executar a função NextJS localmente:

npm run dev

Abra a URL do endpoint para enviar um e-mail: http://localhost/api/email

3. Enviar e-mail em produção

Implementar a função no Vercel:

vercel

Abra a URL do endpoint para enviar um e-mail: https://nome-do-seu-projeto.vercel.app/api/email