pentacent / keila

Open Source Newsletter Tool.
https://keila.io
GNU Affero General Public License v3.0
1.25k stars 61 forks source link

Sender SMTP Failing #249

Closed Nickster258 closed 7 months ago

Nickster258 commented 7 months ago

Hello,

I have been configuring and testing Keila off and on for the past month. I found the only way to get SMTP to work is by using a Postfix container in the stack of containers for Keila. This configuration works for sending registration and password reset emails, but it fails when sending campaign emails.

This is a snippet from sending a password reset email:

[postfix]  | 2023-11-14T15:46:23.407414+00:00 8a714df03980 postfix/smtpd[171]: connect from keila_keila_1.dns.podman[10.89.8.115]
[postfix]  | 2023-11-14T15:46:23.455475+00:00 8a714df03980 postfix/smtpd[171]: 6F1FB25ACC8C: client=keila_keila_1.dns.podman[10.89.8.115]
[postfix]  | 2023-11-14T15:46:23.457294+00:00 8a714df03980 postfix/cleanup[174]: 6F1FB25ACC8C: message-id=<messageid>
[postfix]  | 2023-11-14T15:46:23.560914+00:00 8a714df03980 postfix/qmgr[148]: 6F1FB25ACC8C: from=<from>, size=840, nrcpt=1 (queue active)
[postfix]  | 2023-11-14T15:46:23.561176+00:00 8a714df03980 postfix/smtpd[171]: disconnect from keila_keila_1.dns.podman[10.89.8.115] ehlo=1 mail=1 rcpt=1 data=1 quit=1 commands=5
[keila]    | 15:46:23.561 request_id=id [info] Sent 200 in 197ms
[postfix]  | 2023-11-14T15:46:23.863035+00:00 8a714df03980 postfix/smtp[175]: 6F1FB25ACC8C: to=<me@email>, relay=postserver[serveraddress]:587, delay=0.43, delays=0.13/0.04/0.04/0.22, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 9C9B38037881)
[postfix]  | 2023-11-14T15:46:23.863774+00:00 8a714df03980 postfix/qmgr[148]: 6F1FB25ACC8C: removed

This is when trying to send a campaign email:

[postfix]  | 2023-11-14T15:45:32.969344+00:00 8a714df03980 postfix/smtpd[171]: connect from keila_keila_1.dns.podman[10.89.8.115]
[postfix]  | 2023-11-14T15:45:32.971368+00:00 8a714df03980 postfix/smtpd[171]: disconnect from keila_keila_1.dns.podman[10.89.8.115] ehlo=1 quit=1 commands=2
[postfix]  | 2023-11-14T15:45:32.973071+00:00 8a714df03980 postfix/smtpd[171]: connect from keila_keila_1.dns.podman[10.89.8.115]
[postfix]  | 2023-11-14T15:45:32.974722+00:00 8a714df03980 postfix/smtpd[171]: disconnect from keila_keila_1.dns.podman[10.89.8.115] ehlo=1 quit=1 commands=2
[keila]    | 15:45:32.974 [warning] Failed sending email to me@email for campaign nmc_magwDjLk: {:retries_exceeded, {:missing_requirement, '10.89.8.114', :auth}}

I am not sure how I am getting an auth error there, and not also when trying to reset password or register a new user.

This is what my compose file looks like:

version: "3"

services:
  keila:
    image: pentacent/keila:latest
    ports:
      - "4000:4000"
    depends_on:
      - postgres
    environment:
      SECRET_KEY_BASE: "base"
      DB_URL: "connectionstring"
      KEILA_PASSWORD: "password"
      URL_HOST: "hostname"
      URL_SCHEMA: "https"
      MAILER_SMTP_HOST: postfix
      MAILER_SMTP_PORT: 25
      MAILER_SMTP_USER: "username"
      MAILER_SMTP_PASSWORD: "password"
      MAILER_SMTP_FROM_EMAIL: "from"
    volumes:
      - /data/podman/pods/keila/keila:/app/uploads:Z

  postgres:
    image: postgres:alpine
    ports:
      - "5432:5432"
    environment:
      POSTGRES_PASSWORD: password
    volumes:
      - /data/podman/pods/keila/postgres:/var/lib/postgresql/data:Z

  postfix:
    image: mwader/postfix-relay
    environment:
      - POSTFIX_append_dot_mydomain=no
      - POSTFIX_biff=no
      - POSTFIX_config_directory=/etc/postfix
      - POSTFIX_inet_interfaces=all
      - POSTFIX_inet_protocols=all
      - POSTFIX_mailbox_size_limit=0
      - POSTFIX_mydestination=hostname, localhost.localdomain, , localhost
      - POSTFIX_myhostname=hostname
      - POSTFIX_mynetworks=10.0.0.0/8
      - POSTFIX_recipient_delimiter=+
      - POSTFIX_relayhost=[postserver]:587
      - POSTFIX_smtp_sasl_auth_enable=yes
      - POSTFIX_smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd
      - POSTFIX_smtp_sasl_security_options=noanonymous
      - POSTFIX_smtpd_banner="$myhostname ESMTP $mail_name (RHEL)"
      - POSTFIX_smtpd_relay_restrictions=permit_mynetworks,permit_sasl_authenticated,defer_unauth_destination
      - POSTFIX_smtpd_use_tls=no
    volumes:
      - /data/podman/pods/keila/postfix/sasl_passwd.db:/etc/postfix/sasl_passwd.db:Z

This compose is then utilized by podman-compose and ran in a Podman environment.

From my own analysis, the username/password used in MAILER_SMTP_USER and MAILER_SMTP_PASSWORD do not matter, and works despite them being wrong. Can the sender be configured similarly, without authentication?

Let me know if any more information is needed. Thanks!

Nickster258 commented 7 months ago

I solved the issue. I've spent the last day or so puzzled by this problem but resolved it as I never configured client authentication. I was able to make a user and password in that postfix container for this purpose.

wmnnd commented 7 months ago

Did you use the new MAILER_ENABLE_SSL/MAILER_ENABLE_STARTTLS options that were introduced with the latest release? They are mandatory if you’re using SSL/TLS or STARTTLS.

Nickster258 commented 7 months ago

I did not. My issue was postfix was authenticating to its post server fine, but nothing was configured to authenticate to postfix. I went through this to configure that and put the credentials in both the container environment variables and the sender configs.