Coder Social home page Coder Social logo

postfix-sendgrid's Introduction

Postfix to sendgrid mail relay

Docker

Very simple mail relay, just set the APIKEY environment variable and you should be good to go.

This Docker image automatically updates whenever there is an update to the underlying Alpine image and/or Postfix is updated in the Alpine package repository. (See https://github.com/marius/postfix-sendgrid/actions for how this is implemented)

Heavily inspired by alterrebe/docker-mail-relay and simenduev/postfix-relay.

Warning

This assumes the host is running behind a firewall, you probably don't want to run this container exposed to the internet.

Docker run

docker run -d -e APIKEY=YOUR_KEY -p 25:25 ghcr.io/marius/postfix-sendgrid

Docker compose

  mailrelay:
    image: ghcr.io/marius/postfix-sendgrid
    environment:
      APIKEY: YOUR_KEY
    ports:
      - "25:25"

Using a secret:

secrets:
  sendgrid_apikey:
    file: /tank/docker/secrets/sendgrid_apikey

services:
  mailrelay:
    image: ghcr.io/marius/postfix-sendgrid
    environment:
      APIKEY_FILE: /run/secrets/sendgrid_apikey
    ports:
      - "25:25"
    secrets:
      - sendgrid_apikey

Testing

On the host:

ruby -r net/smtp -e 'Net::SMTP.start("localhost") { |s| s.send_mail "From: [email protected]\r\n\r\nHello via sendgrid", "[email protected]", "[email protected]" }'

From another container:

host# docker run -it --rm --add-host host.docker.internal:host-gateway ubuntu
container# apt update && apt install ruby -y
container# ruby -r net/smtp -e 'Net::SMTP.start("host.docker.internal") { |s| s.send_mail "From: [email protected]\r\n\r\nHello via sendgrid", "[email protected]", "[email protected]" }'

Sending email from other containers

Example Watchtower docker compose config

  watchtower:
    image: containrrr/watchtower
    environment:
      WATCHTOWER_NOTIFICATIONS: email
      WATCHTOWER_NOTIFICATION_EMAIL_TO: [email protected]
      WATCHTOWER_NOTIFICATION_EMAIL_FROM: [email protected]
      WATCHTOWER_NOTIFICATION_EMAIL_SERVER: host.docker.internal
      WATCHTOWER_NOTIFICATION_EMAIL_SERVER_TLS_SKIP_VERIFY: "true"
      WATCHTOWER_NOTIFICATION_EMAIL_DELAY: 120
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    extra_hosts:
      - host.docker.internal:host-gateway

The delay is important, otherwise Watchtower might not be able to send emails.

postfix-sendgrid's People

Contributors

marius avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.