Skip to content

Instantly share code, notes, and snippets.

@danhunsaker
Forked from sanderson/Environment Variables
Last active December 15, 2019 23:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danhunsaker/6822868e1b20f086aa2b137d1b7fd4a3 to your computer and use it in GitHub Desktop.
Save danhunsaker/6822868e1b20f086aa2b137d1b7fd4a3 to your computer and use it in GitHub Desktop.
Configuring Nanobox to Use nullmailer

nullmailer and Nanobox

Start by adding the environment variables (below) to your app, and merging the boxfile.yml entries into your own boxfile.yml. The script, here, is pulled in automatically by the git.io shortlink in the transform hook, so you don't need to add that.

Environment Variables

The values of the various evars should be provided by your SMTP service provider, but here's a quick overview of the variables and what they each mean and do:

  • SMTP_USER={smtp-username} The username provided by your SMTP provider for logging on and sending emails. Might be a full email address.

  • SMTP_PASS={smtp-password} The password used to log in to that account.

  • SMTP_HOST={smtp-host} The domain name of the SMTP server to connect to.

  • SMTP_PORT={smtp-port} The port to connect with. The official ones (which may be blocked by your cloud hosting provider, so be sure to check) are 25 and 587 for standard, unencrypted connections, and 465 for connecting over encrypted SSL/TLS. A common nonstandard port is 2525, which acts much the same as 25 and 587. One thing to note, though, is that port 25 is only intended for use by email servers talking to each other, so you'll usually want 587 instead.

  • SMTP_TLS=starttls|ssl|tls|none Whether to use an encrypted connection or not. none specifies no encryption, and is strongly recommended against. ssl and tls both specify connecting over SSL/TLS, generally on port 465. starttls allows the use of encryption over the non-SSL/TLS ports, by upgrading the connection after it has been established. This is generally the recommended option unless you're using port 465.

  • SMTP_AUTH=login|plain The SMTP Authentication mechanism. This is almost always login, but some servers only support plain; check with your provider for which they prefer.

That should be everything.

# add nullmailer as an extra package
run.config:
...
extra_packages:
- nullmailer
# curl the setup-nullmailer script and run it as a transform hook
deploy.config:
transform:
- bash <(curl -sL https://git.io/vAoIZ)
# start the nullmailer server in whatever component(s) is/are sending mail
web.site:
start:
mail: /data/libexec/nullmailer/nullmailer-send
#!/usr/bin/env bash
ln -sf /data/libexec/nullmailer/sendmail /data/bin/
mkdir -p /data/var/spool/nullmailer/{failed,queue,tmp}
mkfifo /data/var/spool/nullmailer/trigger
echo "${APP_NAME}" > /data/etc/nullmailer/defaulthost
echo "nanoapp.io" > /data/etc/nullmailer/defaultdomain
echo "${APP_NAME}.nanoapp.io" > /data/etc/nullmailer/me
echo "${SMTP_USER}" > /data/etc/nullmailer/adminaddr
if [[ -n "${SMTP_PORT}" ]]; then
options="--port=${SMTP_PORT}"
fi
if [[ "${SMTP_TLS}" == "tls" || "${SMTP_TLS}" == "ssl" ]]; then
options="${options} --tls"
elif [[ "${SMTP_TLS}" == "starttls" ]]; then
options="${options} --starttls"
fi
if [[ "${SMTP_AUTH}" == "login" ]]; then
options="${options} --auth-login"
fi
echo "${SMTP_HOST} smtp --user='${SMTP_USER}' --pass='${SMTP_PASS}' ${options}" > /data/etc/nullmailer/remotes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment