Package: localstack-extension-mailhog
LocalStack Mailhog ExtensionWeb and API based STMP testing directly in LocalStack usingMailHog.If the standard configuration is used, LocalStack will serve the UI throughhttp://mailhog.localhost.localstack.cloud:4566orhttp://localhost:4566/mailhog/.
It will also configureSMTP_HOSTautomatically, which points all services using SMTP, includingSES, to MailHog.Install from GitHub repositoryInstall the extension directly from the GitHub repository by running:localstackextensionsinstall"git+https://github.com/localstack/localstack-extensions/#egg=localstack-mailhog-extension&subdirectory=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/Integration with LocalStackWhen 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:$awslocalsesverify-email-identity--email-addressuser1@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.ConfigureYou can use theMailHog configuration environment variablesto configure the extension.
When using the CLI, you can add them by usingDOCKER_FLAGS='-e MH_<var>=<val> -e ...'.
If you are using docker compose, simply add them as environment variables to the container.DevelopmentInstall local development versionTo 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 runmakeinstallThen, to enable the extension for LocalStack, runlocalstackextensionsdevenable.You can then start LocalStack withEXTENSION_DEV_MODE=1to load all enabled extensions:EXTENSION_DEV_MODE=1localstackstartKnown LimitationsThe MailHog UI supports real-time updates through websockets, which is currently not supported through the default:4566port.
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"])LicensingNo modifications were made to MailHog, which is licensed under MIT license:https://github.com/mailhog/MailHog/blob/master/LICENSE.mdThe extension code is licensed under Apache License Version 2.0