Module: utils/emailSender

Email transport abstraction for transactional emails.

Supports three transports selected by environment variables:

  1. Resend — set RESEND_API_KEY (recommended for production).
  2. SMTP — set SMTP_HOST + SMTP_PORT (+ optional SMTP_USER, SMTP_PASS).
  3. Console — fallback when neither is configured (dev/test only).

All transports expose the same sendEmail() interface so callers never need to know which transport is active.

Source:

Methods

(static) escapeHtml(str) → {string}

Escape HTML special characters to prevent injection in email templates.

Parameters:
Name Type Description
str string
Source:
Returns:
Type
string

(static) getTransportName() → {string}

Get the name of the active email transport.

Source:
Returns:

"resend" | "smtp" | "console".

Type
string

(static) sendEmail(payload) → {Promise.<void>}

Send a transactional email using the configured transport.

Parameters:
Name Type Description
payload EmailPayload

Email to send.

Source:
Throws:

If the transport fails (caller should handle gracefully).

Type
Error
Returns:
Type
Promise.<void>

(static) sendVerificationEmail(email, token, userName) → {Promise.<void>}

Send a verification email to a newly registered user.

Parameters:
Name Type Description
email string

Recipient email address.

token string

The verification token.

userName string

User's display name for personalisation.

Source:
Returns:
Type
Promise.<void>

(inner) detectTransport() → {Object}

Detect which transport is configured and return a send function.

Source:
Returns:

{ name: string, send: Function }

Type
Object

(async, inner) sendViaConsole(payload)

Console fallback — logs the email to stdout for development.

Parameters:
Name Type Description
payload EmailPayload
Source:

(async, inner) sendViaResend(payload)

Send an email using the Resend HTTP API.

Parameters:
Name Type Description
payload EmailPayload
Source:

(async, inner) sendViaSmtp(payload)

Send an email using SMTP via Node's built-in net module. Uses a minimal SMTP client — for production, consider nodemailer. Falls back to console logging if the connection fails.

Parameters:
Name Type Description
payload EmailPayload
Source:

Type Definitions

EmailPayload

Type:
  • Object
Properties:
Name Type Attributes Description
to string

Recipient email address.

subject string

Email subject line.

html string

HTML body.

text string <optional>

Plain-text fallback body.

Source: