Sign inSign up

loganmarchione/docker-postfixrelay

By loganmarchione

•Updated 7 days ago

Image
2

1M+

loganmarchione/docker-postfixrelay repository overview

⁠docker-postfixrelay

CI/CD Docker Image Size (latest semver)

Runs Postfix (as a relay) in Docker

⁠Explanation

  • This runs Postfix (as a relay) in Docker.
  • Most home ISPs block port 25, so outbound emails must be relayed through an external SMTP server (e.g., Gmail).
  • This container acts as a single collections point for devices needing to send email.
  • ⚠️ Postfix acts as an open relay. As such, this is not meant to be run on the internet, only on a trusted internal network! ⚠️
        Internal (LAN) network                                        Public internet

------------------
|                |
| Device sending |                            |   |
| email alert    | -------------              |   |
|                |             |              |   |
------------------             |              |   |
                               |              | F |
------------------             v              | i |
|                |       ------------------   | r |    -----------------------------       -------------------
| Device sending |       |                |   | e |    |                           |       |                 |
| email alert    | ----> | This container | --| w |--> | SMTP server (e.g., Gmail) | ----> | Recipient email |
|                |       |                |   | a |    |                           |       |                 |
------------------       ------------------   | l |    -----------------------------       -------------------
                               ^              | l |
------------------             |              |   |
|                |             |              |   |
| Device sending |             |              |   |
| email alert    | -------------              |   |
|                |
------------------

⁠Requirements

  • You must already have an account on an external SMTP server (e.g., Gmail, AWS SES, etc...).
  • Your external SMTP server must be using encryption (i.e., plaintext is not allowed)

⁠Docker image information

⁠Docker image tags
  • latest: Latest version
  • X.X.X: Semantic version⁠ (use if you want to stick on a specific version)
⁠Environment variables
VariableRequired?DefinitionExampleComments
TZYesTimezoneAmerica/New_Yorkhttps://en.wikipedia.org/wiki/List_of_tz_database_time_zones⁠
RELAY_HOSTYesPublic SMTP server to usesmtp.gmail.com
RELAY_PORTYesPublic SMTP port to use587
RELAY_USERNoAddress to login to $RELAY_HOSTSMTP username
RELAY_PASSNoPassword to login to $RELAY_HOSTSMTP passwordIf using Gmail 2FA, you will need to setup an app password
RELAY_SUBMISSIONSNo (default: false)Use of submissions/TLS to $RELAY_HOSTtrueNeeded when the server requests submissions/implicit TLS (enables Postfix's tls_wrappermode (doc)⁠).
TEST_EMAILNoAddress to receive test email[email protected]⁠If not set, test email will not be sent
TEST_EMAIL_SUBJECTNo (default: "Postfix relay test")Subject of test emailDestroy After ReadingUseful if you're running multiple instances and want to tell them apart
MYORIGINNoDomain of the "from" addressdomain.comNeeded for things like AWS SES where the domain must be set
FROMADDRESSNoChanges the "from" address[email protected]⁠Needed for some SMTP services where the FROM address needs to be set, fixes issue 19⁠
MYNETWORKSNo (default: 0.0.0.0/0)Networks that Postfix will forward mail for1.2.3.4/24, 5.6.7.8/24Single or multiple trusted networks separated with a comma
MSG_SIZENo (default: 10240000)Postfix message_size_limit in bytes30720000
LOG_DISABLENo (default: false)Setting to true disables loggingtrue
⁠Ports
Port on hostPort in containerComments
Choose at your discretion25Postfix SMTP server
⁠Volumes
Volume on hostVolume in containerComments
Choose at your discretion/var/spool/postfixUsed to store Postfix's mail spool
⁠Example usage

Below is an example docker-compose.yml file.

version: '3'
services:
  postfixrelay:
    container_name: docker-postfixrelay
    restart: unless-stopped
    environment:
      - TZ=America/New_York
      - RELAY_HOST=smtp.gmail.com
      - RELAY_PORT=587
      # comment out if using secrets
      - [email protected]
      - RELAY_PASS=your_password_here
      # uncomment below if using secrets
      # - RELAY_USER_FILE=/run/secrets/RELAY_USER_FILE
      # - RELAY_PASS_FILE=/run/secrets/RELAY_PASS_FILE
      - RELAY_SUBMISSIONS=true
      - [email protected]
      - TEST_EMAIL_SUBJECT=Destroy After Reading
      - MYORIGIN=domain.com
      - [email protected]
      - MYNETWORKS=1.2.3.4/24
      - MSG_SIZE=30720000
      - LOG_DISABLE=true
    # uncomment below if using secrets
    # secrets:
    #   - RELAY_USER_FILE
    #   - RELAY_PASS_FILE
    networks:
      - postfixrelay
    ports:
      - '25:25'
    volumes:
      - 'postfixrelay_data:/var/spool/postfix'
    image: loganmarchione/docker-postfixrelay:latest

networks:
  postfixrelay:

volumes:
  postfixrelay_data:
    driver: local

# uncomment below if using secrets
# secrets:
#    RELAY_USER_FILE:
#      file: ./relay_user.txt
#    RELAY_PASS_FILE:
#      file: ./relay_pass.txt
⁠Debugging only

Below is an example of running locally (used to edit/test/debug).

# Build the Dockerfile
docker compose -f docker-compose-dev.yml up -d

# View logs
docker compose -f docker-compose-dev.yml logs -f

# Destroy when done
docker compose -f docker-compose-dev.yml down

Tag summary

Content type

Image

Digest

sha256:968fa7581…

Size

10.5 MB

Last updated

7 days ago

docker pull loganmarchione/docker-postfixrelay