Hi, I'm having trouble getting my e-mails to go through my HAProxy.
My postfix container is not exposed on the Internet. My HAProxy machine is in a separate network.
When setting the ENABLE_PROXY_PROTOCOL=haproxy
parameter, all e-mails incoming to the postfix container need to go through the HAProxy.
For example, if I set POSTFIX_SERVER=postfix
in simplelogin.env
, I get the following error in the SimpleLogin email
container:
2024-05-13 17:58:37,012 - SL - ERROR - 1 - "/code/app/mail_sender.py:196" - _send_to_smtp() - 85a0de33-f7aa-413c-bff8-a8bac3b85906 - Could not send message to smtp server postfix:25
Traceback (most recent call last):
File "/usr/local/lib/python3.10/smtplib.py", line 398, in getreply
line = self.file.readline(_MAXLINE + 1)
File "/usr/local/lib/python3.10/socket.py", line 705, in readinto
return self._sock.recv_into(b)
TimeoutError: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/code/app/mail_sender.py", line 148, in _send_to_smtp
with SMTP(
File "/usr/local/lib/python3.10/smtplib.py", line 255, in __init__
(code, msg) = self.connect(host, port)
File "/usr/local/lib/python3.10/smtplib.py", line 343, in connect
(code, msg) = self.getreply()
File "/usr/local/lib/python3.10/smtplib.py", line 401, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed: "
smtplib.SMTPServerDisconnected: Connection unexpectedly closed: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/smtplib.py", line 398, in getreply
line = self.file.readline(_MAXLINE + 1)
File "/usr/local/lib/python3.10/socket.py", line 705, in readinto
return self._sock.recv_into(b)
TimeoutError: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/code/app/mail_sender.py", line 148, in _send_to_smtp
with SMTP(
File "/usr/local/lib/python3.10/smtplib.py", line 255, in __init__
(code, msg) = self.connect(host, port)
File "/usr/local/lib/python3.10/smtplib.py", line 343, in connect
(code, msg) = self.getreply()
File "/usr/local/lib/python3.10/smtplib.py", line 401, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed: "
smtplib.SMTPServerDisconnected: Connection unexpectedly closed: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/smtplib.py", line 398, in getreply
line = self.file.readline(_MAXLINE + 1)
File "/usr/local/lib/python3.10/socket.py", line 705, in readinto
return self._sock.recv_into(b)
TimeoutError: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/code/app/mail_sender.py", line 148, in _send_to_smtp
with SMTP(
File "/usr/local/lib/python3.10/smtplib.py", line 255, in __init__
(code, msg) = self.connect(host, port)
File "/usr/local/lib/python3.10/smtplib.py", line 343, in connect
(code, msg) = self.getreply()
File "/usr/local/lib/python3.10/smtplib.py", line 401, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed: "
smtplib.SMTPServerDisconnected: Connection unexpectedly closed: timed out
And in the postfix
container logs:
May 13 17:58:37 silo postfix/smtpd[628]: warning: haproxy read: EOF
May 13 17:58:37 silo postfix/smtp[633]: 9F75A1532C: to=<***@***.fr>, relay=email[192.168.0.4]:20381, delay=11, delays=0.39/0.01/0/10, dsn=2.0.0, status=sent (250 Message accepted for delivery)
May 13 17:58:37 silo postfix/qmgr[86]: 9F75A1532C: removed
May 13 17:58:37 silo postfix/smtpd[628]: connect from sl-email-1.sl_default[192.168.0.4]
May 13 17:58:37 silo postfix/smtpd[628]: disconnect from sl-email-1.sl_default[192.168.0.4] commands=0/0
Therefore, I have to set POSTFIX_SERVER
with the hostname of my HAProxy machine in order for my e-mails to go through it, then to the postfix container.
But when I do this, I have another error:
2024-05-13 18:21:03,895 - SL - ERROR - 1 - "/code/app/mail_sender.py:196" - _send_to_smtp() - b7b44223-7c3a-4f66-8cfd-e9440a90b340 - Could not send message to smtp server ct-proxy.home:25
Traceback (most recent call last):
File "/code/app/mail_sender.py", line 172, in _send_to_smtp
smtp.sendmail(
File "/usr/local/lib/python3.10/smtplib.py", line 901, in sendmail
raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {'***@***.fr': (454, b'4.7.1 <***@***.fr>: Relay access denied')}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/code/app/mail_sender.py", line 172, in _send_to_smtp
smtp.sendmail(
File "/usr/local/lib/python3.10/smtplib.py", line 901, in sendmail
raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {'***@***.fr': (454, b'4.7.1 <***@***.fr>: Relay access denied')}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/code/app/mail_sender.py", line 172, in _send_to_smtp
smtp.sendmail(
File "/usr/local/lib/python3.10/smtplib.py", line 901, in sendmail
raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {'***@***.fr': (454, b'4.7.1 <***@***.fr>: Relay access denied')}
And in the postfix
container logs:
May 13 17:41:18 silo postfix/smtpd[160]: connect from 20.mo581.mail-out.ovh.net[46.105.49.208]
May 13 17:41:18 silo postfix/smtpd[160]: 6A15214F9E: client=20.mo581.mail-out.ovh.net[46.105.49.208]
May 13 17:41:18 silo postfix/cleanup[163]: 6A15214F9E: message-id=<wsjrcwgkKVaOrhYykSwTTAdpSDbnhnxRdQWabJu0o@***.fr>
May 13 17:41:18 silo postfix/qmgr[86]: 6A15214F9E: from=<***@***.fr>, size=15943, nrcpt=1 (queue active)
May 13 17:41:18 silo postfix/smtpd[160]: disconnect from 20.mo581.mail-out.ovh.net[46.105.49.208] ehlo=1 mail=1 rcpt=1 data=1 quit=1 commands=5
May 13 17:41:18 silo postfix/smtpd[160]: connect from ct-docker.home[10.0.3.7]
May 13 17:41:18 silo postfix/smtpd[160]: NOQUEUE: reject: RCPT from ct-docker.home[10.0.3.7]: 454 4.7.1 <***@***.fr>: Relay access denied; from=<sl.lmycyibvgaycyibrgi2dgnzygfoq.oweiy5yulwupg@***.fr> to=<***@***.fr> proto=ESMTP helo=<[192.168.0.4]>
May 13 17:41:18 silo postfix/smtpd[160]: disconnect from ct-docker.home[10.0.3.7] ehlo=1 mail=1 rcpt=0/1 rset=1 quit=1 commands=4/5
May 13 17:41:19 silo postfix/smtpd[160]: connect from ct-docker.home[10.0.3.7]
May 13 17:41:19 silo postfix/smtpd[160]: NOQUEUE: reject: RCPT from ct-docker.home[10.0.3.7]: 454 4.7.1 <***@***.fr>: Relay access denied; from=<sl.lmycyibvgaycyibrgi2dgnzygfoq.oweiy5yulwupg@***.fr> to=<***@***.fr> proto=ESMTP helo=<[192.168.0.4]>
May 13 17:41:19 silo postfix/smtpd[160]: disconnect from ct-docker.home[10.0.3.7] ehlo=1 mail=1 rcpt=0/1 rset=1 quit=1 commands=4/5
May 13 17:41:19 silo postfix/smtpd[160]: connect from ct-docker.home[10.0.3.7]
May 13 17:41:19 silo postfix/smtpd[160]: NOQUEUE: reject: RCPT from ct-docker.home[10.0.3.7]: 454 4.7.1 <***@***.fr>: Relay access denied; from=<sl.lmycyibvgaycyibrgi2dgnzygfoq.oweiy5yulwupg@***.fr> to=<***@***.fr> proto=ESMTP helo=<[192.168.0.4]>
May 13 17:41:19 silo postfix/smtpd[160]: disconnect from ct-docker.home[10.0.3.7] ehlo=1 mail=1 rcpt=0/1 rset=1 quit=1 commands=4/5
May 13 17:41:19 silo postfix/smtp[164]: 6A15214F9E: to=<***@***.fr>, relay=email[192.168.0.4]:20381, delay=1.5, delays=0.41/0.02/0/1.1, dsn=2.0.0, status=sent (250 Message accepted for delivery)
May 13 17:41:19 silo postfix/qmgr[86]: 6A15214F9E: removed
If I remove the mynetworks_style = subnet
and set mynetworks
with the IP/32 of my HAProxy machine, the e-mails are forwarded correctly.
Do I miss something in the container configuration, or do I really need to set the mynetworks
setting in order for this to work properly ?
I already made a patch to replace mynetworks_style
with mynetworks
with an env variable, so I can make a PR.