
Summary
Key points of this document
- Where are the design challenges?
- How to define boundaries?
- Details that make a difference in implementation
Overview
Email sending functionality is an area with significant impact if accidentally sent to production recipients. In a development environment, a mechanism should be prepared to confirm the body and recipients without sending actual emails. In an email sending development environment, it is necessary to achieve both not sending actual emails and accurately confirming the content of the transmission.
Where are the design challenges?
If email functionality is developed and confirmed using production SMTP, there is a risk that test data will be sent to actual recipients. Conversely, if email confirmation is postponed, template corruption or incorrect links may be found in production.
Emails are often sent asynchronously, separating screen operations from transmission results. Templates include environment-specific URLs and merge data, and sometimes handle attachments.
Email functionality quality cannot be confirmed solely by a success display on the screen. Unless the recipient, subject, body, links, attachments, character encoding issues, and missing template variables are checked, problems will surface when the email reaches the user.
How to define boundaries?
Add an email preview service to Docker Compose and point the development environment's SMTP to it. In staging, implement guards to prevent sending to unpermitted domains and recipient substitution.
In the design, separate email sending paths for development, testing, and production. Place an email preview service in Docker Compose and point Laravel or Node.js SMTP settings to it only during development. Production SMTP credentials are not brought to local environments.
Details that make a difference in implementation
In app settings, manage SMTP host, port, sender, and base URL with environment variables. Separate email sending processes into template generation and sending, and in tests, confirm that the body contains the necessary information.
On the application side, email sending should not be written directly to SMTP, but rather passed through a notification service or mailer interface. In tests, verify sending requests with a fake mailer, and for local confirmation, check the actual HTML and text on the preview screen.
- Set the development environment's SMTP_HOST to a fixed value pointing to the preview container, configuring it so that external sending is not possible.
- Prepare preview fixtures for email templates to confirm the body content for different states.
- Switch link URLs and senders using environment variables to prevent development URLs from mixing into production emails.
Observe how it breaks
In verification, trigger major emails such as registration, notification, reset, and approval locally, and check the subject, recipient, body, links, and attachments. Also test that emails cannot be sent to external recipients in staging.
In verification, preview representative cases such as registration, invitation, password reset, notifications, and emails with attachments. In CI, test that email sending requests occurred and that recipients and template variables are correct.
Discarded options and trade-offs
In an environment where no actual emails are sent, spam filtering and DNS settings cannot be confirmed. Delivery deliverability should be confirmed with separate production-equivalent tests, and prioritizing prevention of accidental sending in daily development is safer.
A preview environment alone cannot determine the deliverability of production SMTP or spam filtering. In development, prioritize preventing accidental sending, and in staging, perform limited checks closer to actual sending. It is necessary to divide roles for each environment.
Decision criteria to leave for the team
For email functionality, it is more important not to send incorrectly than to be able to send. By simply adding a preview SMTP to the Docker development environment, you can achieve both body confirmation and safety.
Email functionality is not complete with just successful sending. By creating an environment where emails can be safely previewed on Docker, you can confirm the content that reaches users while preventing accidental sending.


