Created
January 23, 2026 00:42
-
-
Save jrdn91/47377ff7acd5515103752e71ba3d4ca3 to your computer and use it in GitHub Desktop.
Basic dev email client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createDevEmailClient } from '@/lib/email/dev-email-client' | |
| import { createProductionEmailClient } from '@/lib/email/production-email-client' | |
| export function createEmailClient(environment: 'development' | 'production') { | |
| if (environment === 'development') { | |
| return createDevEmailClient() | |
| } | |
| return createProductionEmailClient() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import nodemailer from 'nodemailer' | |
| import type { Transporter } from 'nodemailer' | |
| import type { EmailClient } from '@/lib/email/email-client-types' | |
| // Email configuration | |
| const emailConfig = { | |
| host: 'localhost', | |
| port: 1025, | |
| secure: false, | |
| } | |
| export function createDevEmailClient(): EmailClient { | |
| const transporter: Transporter = nodemailer.createTransport({ | |
| host: emailConfig.host, | |
| port: emailConfig.port, | |
| secure: emailConfig.secure, | |
| }) | |
| return { | |
| async sendEmail({ from, to, subject, content }) { | |
| await transporter.sendMail({ | |
| from, | |
| to, | |
| subject, | |
| html: content, | |
| }) | |
| }, | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version: "3.9" | |
| services: | |
| mailpit: | |
| image: axllent/mailpit:latest | |
| container_name: dev-mailpit | |
| ports: | |
| - "1025:1025" # SMTP | |
| - "8025:8025" # Web UI | |
| # Add a small named volume if you want messages to survive container restarts | |
| volumes: | |
| - mailpit_data:/data | |
| environment: | |
| MP_DATABASE: /data/mailpit.db | |
| volumes: | |
| mailpit_data: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export interface EmailClient { | |
| sendEmail: (args: { | |
| from: string | |
| to: string | |
| subject: string | |
| content: string | |
| replyTo?: string | |
| }) => Promise<void> | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const emailHTML = await renderSomeEmailHTML(data.otp) | |
| const emailClient = createEmailClient( | |
| process.env.NODE_ENV as 'development' | 'production', | |
| ) | |
| await emailClient.sendEmail({ | |
| from: 'onboarding@example.com', | |
| to: data.email, | |
| subject: 'Here is your verification code', | |
| content: emailHTML, | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment