Skip to main content

LocalStack Mailhog Extension

Install LocalStack Extension

Web and API based SMTP testing directly in LocalStack using MailHog.

If the standard configuration is used, LocalStack will serve the UI through http://mailhog.localhost.localstack.cloud:4566 or http://localhost:4566/mailhog/. It will also configure SMTP_HOST automatically, which points all services using SMTP, including SES, to MailHog.

Install

Install the extension either via our extensions manager at https://app.localstack.cloud, or via the CLI

localstack extensions install localstack-extension-mailhog

After starting LocalStack, you should see these lines in the log:

2023-07-26T10:00:08.072  INFO --- [  MainThread] mailhog.extension          : serving mailhog extension on host: http://mailhog.localhost.localstack.cloud:4566
2023-07-26T10:00:08.072  INFO --- [  MainThread] mailhog.extension          : serving mailhog extension on path: http://localhost:4566/mailhog/

Install from GitHub repository

Alternatively, you can install the latest unreleased version directly from the GitHub repository by running:

localstack extensions install "git+https://github.com/localstack/localstack-extensions/#egg=localstack-mailhog-extension&subdirectory=mailhog"

Integration with LocalStack

When using this extension, LocalStack is automatically configured to use the MailHog SMTP server when sending emails. For example, if you run the following SES commands:

$ awslocal ses verify-email-identity --email-address user1@yourdomain.com
$ awslocal ses send-email \                                              
    --from user1@yourdomain.com \
    --message 'Body={Text={Data="Hello from LocalStack to MailHog"}},Subject={Data=Test Email}' \
    --destination 'ToAddresses=recipient1@example.com'
{
    "MessageId": "ktrmpmhohorxfbjd-dzebwdgu-odnm-wyvz-pezg-mijejwlvaxtr-psfctr"
}

You should see the mail arriving in MailHog. Screenshot at 2023-07-26 12-08-54

Configure

You can use the MailHog configuration environment variables to configure the extension. When using the CLI, you can add them by using DOCKER_FLAGS='-e MH_<var>=<val> -e ...'. If you are using docker compose, simply add them as environment variables to the container.

Development

Install local development version

To install the extension into localstack in developer mode, you will need Python 3.10, and create a virtual environment in the extensions project.

In the newly generated project, simply run

make install

Then, to enable the extension for LocalStack, run

localstack extensions dev enable .

You can then start LocalStack with EXTENSION_DEV_MODE=1 to load all enabled extensions:

EXTENSION_DEV_MODE=1 localstack start

Known Limitations

The MailHog UI supports real-time updates through websockets, which is currently not supported through the default :4566 port. When you open the UI, you may see this error in the LocalStack logs, which is safe to ignore. The UI won't update automatically though, so you need to click the refresh button.

2023-07-25T18:23:12.465 ERROR --- [-functhread3] hypercorn.error            : Error in ASGI Framework
Traceback (most recent call last):
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/hypercorn/asyncio/task_group.py", line 23, in _handle
await app(scope, receive, send, sync_spawn, call_soon)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/hypercorn/app_wrappers.py", line 33, in __call__
await self.app(scope, receive, send)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/localstack/aws/serving/asgi.py", line 67, in __call__
return await self.wsgi(scope, receive, send)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/localstack/http/asgi.py", line 324, in __call__
raise NotImplementedError("Unhandled protocol %s" % scope["type"])
NotImplementedError: Unhandled protocol websocket
2023-07-25T18:23:12.465 ERROR --- [-functhread3] hypercorn.error            : Error in ASGI Framework
Traceback (most recent call last):
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/hypercorn/asyncio/task_group.py", line 23, in _handle
await app(scope, receive, send, sync_spawn, call_soon)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/hypercorn/app_wrappers.py", line 33, in __call__
await self.app(scope, receive, send)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/localstack/aws/serving/asgi.py", line 67, in __call__
return await self.wsgi(scope, receive, send)
File "/opt/code/localstack/.venv/lib/python3.10/site-packages/localstack/http/asgi.py", line 324, in __call__
raise NotImplementedError("Unhandled protocol %s" % scope["type"])

Licensing

Metadata

Release files for localstack-extension-mailhog 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for localstack-extension-mailhog 0.2.0
File Size Uploaded
localstack_extension_mailhog-0.2.0.tar.gz 7.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for localstack-extension-mailhog 0.2.0
File Interpreter ABI Platform
localstack_extension_mailhog-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 kB

Release files / localstack_extension_mailhog-0.2.0.tar.gz

Download URL localstack_extension_mailhog-0.2.0.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d0ee01865a788f023a88b810d7154665bbf41d1d25040b6a933ef278ee9d24c2
BLAKE2b-256 checksum
How to use checksums
738a97308ff78ae698c3441221e7bf2dd97c43c621039246cb28d62d79e44a71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.6

Release files / localstack_extension_mailhog-0.2.0-py3-none-any.whl

Download URL localstack_extension_mailhog-0.2.0-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e3445f89f10f4c623c053e206855213b7d1623a51cb2dbc6653687baabb87e0
BLAKE2b-256 checksum
How to use checksums
722b184e4d04412f4373577a94ddaa2e278c2fd7fcbc8ac2a83a2b4cfa30a357
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.6

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page