Skip to Content
AwsAWS SES

AWS SES

Next.js & Node v22 ENV

Initialize

import { SESv2Client, SendEmailCommand } from '@aws-sdk/client-sesv2'; const sesClient = new SESv2Client({ region: process.env.AWS_SES_REGION, credentials: { accessKeyId: process.env.AWS_SES_ACCESS_KEY_ID!, secretAccessKey: process.env.AWS_SES_SECRET_ACCESS_KEY!, }, });

Verification

if (!process.env.AWS_SES_REGION || !process.env.AWS_SES_ACCESS_KEY_ID || !process.env.AWS_SES_SECRET_ACCESS_KEY || !process.env.AWS_SES_FROM_EMAIL) { console.error('Missing AWS SES environment variables'); return NextResponse.json({ error: 'Email service configuration error' }, { status: 500 }); }

Send Email

const command = new SendEmailCommand({ FromEmailAddress: process.env.AWS_SES_FROM_EMAIL, Destination: { ToAddresses: [email], }, Content: { Simple: { Subject: { Data: '[HATS Download] Email Verification Code', Charset: 'UTF-8', }, Body: { Text: { Data: `Your verification code is: ${code}\n\nPlease enter this code within 5 minutes.`, Charset: 'UTF-8', }, }, }, }, }); await sesClient.send(command);
Last updated on