Assuming you have access to a web server with support for Docker Compose, you can use this yml config to run the service:
docker-compose.yml
version: '3.4'
services:
post-to-email:
restart: unless-stopped
image: matthiasmullie/post-to-email
container_name: post-to-email
environment:
- ALLOW_ORIGIN=*
- DSN=smtp://user:password@smtp.my-domain.com:port
- RECIPIENT=Matthias Mullie <my-email@example.com>
ports:
- '8080:80'
healthcheck:
test: 'curl --fail http://localhost:80/?SENDER=test@example.com'
interval: 1m
timeout: 10s
retries: 3
start_period: 20s
Now execute docker compose up
(or docker-compose up
) to run the container. This will pull the matthiasmullie/post-to-email
image from Docker Hub and run it exposed on port 8080 with a hard-coded DSN
and RECIPIENT
.
- For
ALLOW_ORIGIN
, enter the domain you want to accept requests from (e.g.https://my-website.com
), or*
to allow requests from anywhere- To prevent abuse, I'd recommend locking things down to a specific domain unless there's a good reason not to
- Read up on Access-Control-Allow-Origin if you want to learn more
DSN
should be your SMTP connection stringRECIPIENT
is the email address you want to receive emails at- This can take either
my-email@example.com
orMy Name <my-email@example.com>
format
- This can take either
While it's possible to include these variables in the data your form will submit, it makes sense to hard-code some of these in the web service, to prevent others from being able to (ab)use your service.
Note: don't forget to replace below DSN & RECIPIENT variables with your own. Check configuration to see what other environment variables are available.
Note: the healthcheck
config is not required, but can be useful to monitor that the service remains up & healthy.