Skip to content

Latest commit

 

History

History
44 lines (36 loc) · 2.81 KB

1-docker-compose.md

File metadata and controls

44 lines (36 loc) · 2.81 KB

Run it with Docker Compose

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 string
    • This usually takes the form of smtp://<username>:<password>@<smtp-server>:<port>
    • For more information, check with your email provider. Here's a link to Gmail and Outlook's documentation
      • Note: If your email account is secured with multi-factor authentication, you may need to create an app password. Here's some documentation for Gmail and Outlook
  • RECIPIENT is the email address you want to receive emails at
    • This can take either my-email@example.com or My Name <my-email@example.com> format

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.