Test Controller and Email Diagnostics
Relevant source files - config/nodemailer.js - controllers/test.controller.js - public/index.html - test-email.js
The Subscription Tracker API provides dedicated tools for verifying the email notification pipeline independently of the long-running Upstash workflow schedules. This includes a manual trigger endpoint, diagnostic logging for the SMTP transporter, and a standalone script for environment verification.
Overview of Diagnostic Tools
The diagnostic suite is designed to bypass the standard context.sleepUntil logic used in the production workflow, allowing developers to immediately verify that the Brevo SMTP configuration and HTML templates are functioning correctly.
| Tool | Entity | Purpose |
|---|---|---|
| Test Controller | sendTestReminder |
API endpoint to send a "1-day reminder" template to a specific subscription owner. |
| Standalone Script | test-email.js |
CLI tool to verify SMTP credentials and connection without starting the Express server. |
| Transporter Check | verifyTransporter |
Diagnostic function that logs detailed connection status and TLS handshakes. |
Sources:controllers/test.controller.js5-49test-email.js1-40config/nodemailer.js32-44
Test Reminder Controller
The sendTestReminder function is the primary entry point for manual email testing. It is exposed via the POST /api/v1/test/send-reminder-email route.
Execution Flow
- Validation: The controller extracts
subscriptionIdfrom the request body controllers/test.controller.js7-11 - Data Retrieval: It fetches the subscription and populates the
userfield to obtain the recipient's name and email address controllers/test.controller.js13-16 - State Check: It ensures the subscription status is
activebefore proceeding controllers/test.controller.js21-24 - Diagnostic Hook: It calls
verifyTransporter()to log the current health of the Nodemailer instance controllers/test.controller.js29-30 - Immediate Dispatch: It calls
sendReminderEmailusing the "1 days before reminder" template type, effectively simulating the final stage of a real workflow controllers/test.controller.js38-42
Diagram: Test Controller Logic Space
The following diagram maps the logical flow of the test controller to the specific code entities involved.
Sources:controllers/test.controller.js1-49config/nodemailer.js32-44utils/send-email.js1-10 (referenced)
Transporter Diagnostics
The system uses nodemailer configured with high-verbosity logging to assist in troubleshooting network or authentication issues, particularly when deployed to environments like Render.
Configuration Settings
The transporter is configured with specific timeouts and logging enabled:
- Timeouts:
connectionTimeout(10s),greetingTimeout(5s), andsocketTimeout(10s) ensure the application does not hang on blocked ports config/nodemailer.js23-25 - Logging:
logger: trueanddebug: trueare enabled to output the full SMTP conversation to the console config/nodemailer.js21-22 - TLS:
rejectUnauthorized: falseis set to allow flexibility in various hosting environments where certificate chains might be incomplete config/nodemailer.js28
verifyTransporter Function
The verifyTransporter function config/nodemailer.js32-44 is an asynchronous utility that wraps transporter.verify(). It logs a success message or catches and formats errors to provide clear feedback in the server logs during startup or test execution.
Sources:config/nodemailer.js13-30config/nodemailer.js32-44
Standalone Email Script
For testing the SMTP pipeline without the overhead of the MongoDB connection or the Express framework, the test-email.js script provides a direct path to the transporter.
Implementation Details
- Environment: It imports the
transporterandaccountEmaildirectly from the config test-email.js1 - Payload: It constructs a hardcoded HTML test email test-email.js12-24
- Execution: Running
node test-email.jstriggerstransporter.sendMail()and logs the raw SMTP response or the error stack test-email.js29-36
Diagram: CLI Diagnostic Flow
This diagram shows how the standalone script interacts with the configuration layer.
[Flowchart Diagram]
Sources:test-email.js1-40config/nodemailer.js13-30
Error Handling and Logging
Both the controller and the diagnostic script implement specific error handling patterns to identify failure points in the email chain.
| Failure Point | Handling Mechanism | Logging Output |
|---|---|---|
| Missing Subscription | Controller returns 404 Not Foundcontrollers/test.controller.js19 |
"subscription not found" |
| Inactive Subscription | Controller returns 400 Bad Requestcontrollers/test.controller.js23 |
"subscription not active" |
| SMTP Auth Failure | verifyTransporter throws error config/nodemailer.js37-42 |
transporter.verify error: [Message] |
| Network Timeout | nodemailer internal timeout triggers config/nodemailer.js23-25 |
Connection timeout |
Sources:controllers/test.controller.js5-49config/nodemailer.js32-44