Skip to content

Conversation

@raulrpearson
Copy link
Contributor

Overview

Drops Mua in favour of the SMTP Swoosh adapter and adjusts the config accordingly. The lock file has also been cleaned up by running mix deps.unlock --unused. Hopefully fixes #112. The new setup relies on :public_key.cacerts_get(), which assumes certificates are installed in the machine running the application.

I've tested against three SMTP setups:

  • Resend using implicit SSL/TLS on port 465 (as far as I can tell).
  • Postmark SMTP (not REST API) using StartTLS on port 587 (as far as I can tell).
  • Locally with no SSL/TLS against Mailpit.

In all cases I have:

MAIL_TRANSPORT=smtp
MAIL_FROM=noreply@myverifieddomain.com
MAIL_FROM_NAME=Claper

Aside from obviously setting transport to SMTP, I'm not sure these matter for the purpose of this PR. I did set up the from variable to a domain I own and verified with Resend and Postmark to rule out emails not being delivered because of that. In the following snippets I've commented out the environment variables whose default value is already suitable.

Resend

Resend works with the following variables:

SMTP_RELAY=smtp.resend.com
SMTP_PORT=465
# SMTP_RETRIES=1
# SMTP_NO_MX_LOOKUPS=false

# SMTP_AUTH=always
SMTP_USERNAME=xxx
SMTP_PASSWORD=xxx

# SMTP_SSL=true
# SMTP_TLS=if_available
# SMTP_SSL_DEPTH=2
SMTP_SSL_SERVER=*.resend.com

It might also work with the 587 port and maybe setting SSL to false and TLS to always, to force StartTLS. The key addition vs before is using SMTP_SSL_SERVER to tell the underlying SSL/TLS implementation to accept a certificate that isn't for the exact relay host. This maybe was being done by Mua under-the-hood while it seems we need to set this explicitly when using the SMTP adapter which relies on gen_smtp.

Postmark

Postmark seems to work with the following variables:

SMTP_RELAY=smtp.postmarkapp.com
SMTP_PORT=587
# SMTP_RETRIES=1
# SMTP_NO_MX_LOOKUPS=false

# SMTP_AUTH=always
SMTP_USERNAME=xxx
SMTP_PASSWORD=xxx

SMTP_SSL=false
SMTP_TLS=always
# SMTP_SSL_DEPTH=2
SMTP_SSL_SERVER=postmarkapp.com

I was not able to get Postmark to deliver my emails, but calling the Swoosh delivery function in IEx returned and "ok queued <id>" tuple. I think I might need to add a credit card to Postmark, which I don't want to do, so I'm counting this as working.

Mailpit

I got Mailpit to work locally with an unsecured connection with the following variables:

SMTP_RELAY=localhost
SMTP_PORT=1025
# SMTP_RETRIES=1
SMTP_NO_MX_LOOKUPS=true

SMTP_AUTH=never
# SMTP_USERNAME=xxx
# SMTP_PASSWORD=xxx

SMTP_SSL=false
SMTP_TLS=never
# SMTP_SSL_DEPTH=2
# SMTP_SSL_SERVER=*.example.com

The key addition here is telling the underlying networking libraries not to try to resolve the relay host name with MX records, if I'm understanding this correctly.

Drops Mua in favour of the SMTP Swoosh adapter and adjusts the config
accordingly. The lock file has also been cleaned up by running `mix deps.unlock
--unused`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SMTP does not work...

1 participant