Skip to content

Instantly share code, notes, and snippets.

@glaszig
Last active June 27, 2023 08:53
Show Gist options
  • Save glaszig/cbfad7afad441b153c1840b23561832d to your computer and use it in GitHub Desktop.
Save glaszig/cbfad7afad441b153c1840b23561832d to your computer and use it in GitHub Desktop.
rails' action mailbox without installing rails on your mail server

forward email to action mailbox without installing rails

rails provides rake tasks to forward mails to action mailbox's relay ingress. that's fine unless you have your mail server(s) on another system and don't want to install rails (and all dependencies, i.e. the ruby runtime).
since the rake tasks basically just upload stdin to your rails app via http you can do everything with curl.

action-mailbox-relayer.sh

#!/usr/bin/env sh
curl -sS -u "actionmailbox:$INGRESS_PASSWORD" \
 -A "Action Mailbox curl relayer" \
 -H "Content-Type: message/rfc822" \
 --data-binary @- \
 $URL
  • the basic auth username actionmailbox is the current default and may be subject to change
  • make sure the INGRESS_PASSWORD environment variable contains your action mailbox password (see rails credentials:edit)
  • supply your rails app's ingress url with the URL env var (URL="https://example.com/rails/action_mailbox/relay/inbound_emails")
  • make sure you use tls in production because you're transporting a password and possibly sensible user data

then configure your mail system to pipe email to this script.

/etc/aliases

# ...
actionmailbox: "|/path/to/action-mailbox-relayer.sh"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment