This is how I got Mastodon to use an external SMTP server to deliver outgoing mail.

I received lots of errors such as ”WARN: Net::SMTPFatalError: 550 Bad HELO – Host impersonating domain name [example.com]”, which resulted in zero emails being sent. I solved it by adding my server’s IP to a TXT record for my domain, looking something like this:

v=spf1 a mx ip4:123.123.123.123 ~all

and then adding this to the .env.production file on my Mastodon server:

SMTP_SERVER=smtp.example.com
SMTP_PORT=465
SMTP_LOGIN=mastodon@example.com
SMTP_PASSWORD=long_password
SMTP_AUTH_METHOD=plain
SMTP_SSL=true
SMTP_ENABLE_STARTTLS_AUTO=true
SMTP_OPENSSL_VERIFY_MODE=none
SMTP_FROM_ADDRESS=mastodon@example.com
SMTP_DELIVERY_METHOD=smtp
SMTP_DOMAIN=localhost

After reloading the Mastodon services should work.

systemctl restart mastodon-sidekiq

systemctl reload mastodon-web