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 [hingst.net]”, 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,
v=spf1 a mx ip4:188.8.131.52 ~all
and then adding this to the .env.production file on my Mastodon server:
SMTP_SERVER=smtp.example.com SMTP_PORT=465 SMTP_LOGINemail@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_ADDRESSfirstname.lastname@example.org SMTP_DELIVERY_METHOD=smtp SMTP_DOMAIN=localhost
After reloading the Mastodon services it should work.
systemctl restart mastodon-sidekiq
systemctl reload mastodon-web
This setup worked for me. Might not work for you.
At first I thought SMTP_DOMAIN should be set to the same domain that the Mastodon instance is on (in my case SMTP_DOMAIN=hingst.net), but that did not work. I instead had to set it to localhost, which resulted in all my emails coming through and not ending up in spam 🙂