Appearance
Email
During development, it is often necessary to send emails for testing purposes. It is important that these test emails are captured and not sent out into the real world. This guide will help you set up email capture in your development environment.
Mailpit
Mailpit is a lightweight SMTP server that can be used to capture and view emails sent from your application during development.
For local development, follow the Mailpit installation instructions found here.
If you need to capture emails in a test/staging environment, you can host Mailpit alongside your site using Forge. Some sites will already have this setup, so it is worth checking the environment variables in Forge before installing your own.
Follow this guide to set up a new Mailpit instance in Forge.
Alternatively, we already have a Mailpit instance running on test2.uk.morphdigital.net which you can use instead of setting up your own (assuming your site is running on test2.uk.morphdigital.net). To use this instance, use the following SMTP details:
| Host | Port |
|---|---|
127.0.0.1 | 1025 |
Environment variables
To configure your application to send emails through Mailpit, you will need to set up environment variables. These can be added to your .env file, or in the environment settings file in Forge.
Here is an example of what the environment variables should look like:
dotenv
MAIL_DRIVER=smtp
MAIL_HOST=127.0.0.1
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=nullYou will need to check the environment variable names in your site's source code, as they may vary depending on the framework or library you are using.
Viewing emails
By default, Mailpit will serve its web interface at http://127.0.0.1:8025. You can access this interface to view emails that your application sends.
If you are running Mailpit on a different host or port, you will need to adjust the URL accordingly. For example, the Mailpit instance running on test2 is accessible at https://mailpit.test2.uk.morphdigital.net. You will need to find the HTTP auth credentials for this instance in BitWarden (search for mailpit.test2.uk.morphdigital.net - HTTP).