It is a kind of simple SMTP server and can be used for mail test during development. Because the container is also published on Docker Hub It's also very easy to deploy.
This time, we will just add an SMTP server to the existing docker project. If you want to check the behavior with
docker run
, please check the document of the distributor.
Add a container to docker-compose.yml
mailhog:
image: mailhog/mailhog
ports:
- "8025:8025"
The 8025
set to ports
is MailHog's default HTTP port.
If you want to do an SMTP test from the host terminal to MailHog on the container
Add -" 1025: 1025 "
to ports
service | default port |
---|---|
HTTP server | 8025 |
SMTP server | 1025 |
After building, when you access http://localhost:8025
, this screen will be displayed.
After that, if you send an email to the MailHog container, you can check it on this screen
For the same accuracy, check with a simple program whether SMTP communication passes normally.
import smtplib
from email.mime.text import MIMEText
def test_mail(fromaddr, toaddr, subject, msg):
m = MIMEText(msg)
m['Subject'] = subject
m['From'] = fromaddr
m['To'] = toaddr
s=smtplib.SMTP(host="mailhog", port=1025)
s.sendmail(fromaddr, toaddr, m.as_string())
s.close()
return "done"
Incoming mail is displayed in a list
You can also check the source and header information from the browser.
It seems that Jim can also test the abnormal system.
To use it, add the following in the mailhog
part of docker-compose.yml
command:
-invite-jim
-jim-accept = 0.5
In the above case, there is a 50% chance that the email will be sent successfully. (Other communication speeds can be set)
In the manual, it says Mail Hog ~
as an option setting, but if you provide that on Docker, it will not work
Please check various options from the following Introduction to Jim
You can also check the setting value from the browser.
By default, emails are stored in memory, so If you restart the container, the received mail will be deleted.