CONSOLE
Loading
Integrate Nodemailer with PhotonRelay in Node.js, Express, and Next.js. Implement connection pooling, custom headers, and sub-second OTP dispatches.
To configure Nodemailer with an SMTP relay, call nodemailer.createTransport({ host: 'mail.photonrelay.com', port: 587, secure: false, auth: { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS } }) and dispatch messages with transporter.sendMail(options). For high-concurrency microservices, enable pool: true with maxConnections: 5 to reuse TCP sockets and slash latency.
npm install nodemailer
# Optional for TypeScript projects:
npm install -D @types/nodemailer
Create a reusable mail client module (mailer.js or mailer.ts):
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
host: "mail.photonrelay.com",
port: 587,
secure: false, // true for port 465, false for 587 STARTTLS
auth: {
user: process.env.PHOTON_SMTP_KEY,
pass: process.env.PHOTON_SMTP_SECRET
},
pool: true, // reuse socket connections
maxConnections: 5,
maxMessages: 100
});
module.exports = transporter;
Without connection pooling, Nodemailer establishes a fresh TCP socket, performs a 3-way handshake, and negotiates a new TLS session for every single email sent. Under heavy concurrency, this exhausts operating system file descriptors.
Setting pool: true maintains persistent open connections to PhotonRelay Anycast nodes, slashing latency down to under 350 milliseconds per dispatch.
async function sendVerificationEmail(recipientEmail, otpCode) {
const info = await transporter.sendMail({
from: '"Security Team" <auth@yourdomain.com>',
to: recipientEmail,
subject: "Your Authentication Code",
text: `Your OTP code is: ${otpCode}`,
html: `<h2>Your Verification Code</h2><p style="font-size:24px;font-weight:bold;color:#4F46E5;">${otpCode}</p>`,
headers: {
'X-Entity-Ref-ID': 'otp_9821'
}
});
console.log("Message delivered: %s", info.messageId);
}
// app/actions/send-email.ts
'use server';
import transporter from '@/lib/mailer';
export async function handleContactForm(formData: FormData) {
const email = formData.get('email') as string;
const message = formData.get('message') as string;
try {
await transporter.sendMail({
from: '"Inquiries" <contact@yourdomain.com>',
to: 'team@yourdomain.com',
subject: `New Contact Submission from ${email}`,
text: message
});
return { success: true };
} catch (error) {
return { success: false, error: 'Dispatch failed' };
}
}
Plug into globally distributed Anycast edge nodes. Enjoy 5,000 free monthly emails and pay-per-use scaling at flat $0.50 per 1,000 emails.
Trademark Notice & Nominative Fair Use: All third-party trademarks, logos, and service marks (SendGrid®, Mailgun®, Amazon SES®, Postmark®, Resend®, Brevo®, SMTP2Go®, SparkPost®) are property of their respective owners and used under 15 U.S.C. § 1115(b)(4).
Photon Console is independent and not affiliated with or endorsed by these providers. Pricing and plan details compiled from public sources as of November 2026. Read full legal disclaimer →