Skip to content

Instantly share code, notes, and snippets.

@sartimo
Created August 21, 2024 08:48
Show Gist options
  • Save sartimo/af81d3c56d93dd50d20eb83fa28139c4 to your computer and use it in GitHub Desktop.
Save sartimo/af81d3c56d93dd50d20eb83fa28139c4 to your computer and use it in GitHub Desktop.
Local Devenv Nodemailer
version: '3'
services:
mailhog:
image: mailhog/mailhog
container_name: mailhog
ports:
- "1025:1025"
- "8025:8025"
import nodemailer from 'nodemailer';
import dotenv from 'dotenv';
dotenv.config();
async function main() {
let transporter;
if (process.env.DEVENV === 'development') {
transporter = nodemailer.createTransport({
host: 'localhost',
port: 1025,
secure: false, // Note that secure should be false for local testing
auth: null, // No auth in local development with Mailhog
});
} else {
transporter = nodemailer.createTransport({
host: 'smtp.resend.com',
port: 465,
secure: true,
auth: {
user: 'resend',
pass: 're_123456789',
},
});
}
const info = await transporter.sendMail({
from: '[email protected]',
to: '[email protected]',
subject: 'Hello World',
html: '<strong>It works!</strong>',
});
console.log('Message sent: %s', info.messageId);
}
main().catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment