Cannot send email via smtp Mailgun setup #22228

Open
opened 2026-02-21 20:16:14 -05:00 by yindo · 3 comments
Owner

Originally created by @tnfsmith on GitHub (Feb 15, 2026).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

v1.13.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Hi, I cannot send email via new feature Human-in-Loop via email as well as any services related Dify itself. Here is the basic config of the Mailgun. I can confirm that these config verify and work with smtp plugin of Dify eco system except Dify email system. Pls check it out.

MAIL_TYPE=smtp
MAIL_DEFAULT_SEND_FROM=welcome@mydomain.com

SMTP_SERVER=smtp.mailgun.org
SMTP_PORT=587

SMTP_USERNAME=welcome@mydomain.com
SMTP_PASSWORD=my_pass_smtp

SMTP_USE_TLS=true
SMTP_OPPORTUNISTIC_TLS=false

EHLO hostname

SMTP_LOCAL_HOSTNAME=mydomain.com

✔️ Expected Behavior

Email with correct smtp config should be sent emails normally.

Actual Behavior

No response

Originally created by @tnfsmith on GitHub (Feb 15, 2026). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version v1.13.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Hi, I cannot send email via new feature Human-in-Loop via email as well as any services related Dify itself. Here is the basic config of the Mailgun. I can confirm that these config verify and work with smtp plugin of Dify eco system except Dify email system. Pls check it out. MAIL_TYPE=smtp MAIL_DEFAULT_SEND_FROM=welcome@mydomain.com SMTP_SERVER=smtp.mailgun.org SMTP_PORT=587 SMTP_USERNAME=welcome@mydomain.com SMTP_PASSWORD=my_pass_smtp SMTP_USE_TLS=true SMTP_OPPORTUNISTIC_TLS=false # EHLO hostname SMTP_LOCAL_HOSTNAME=mydomain.com ### ✔️ Expected Behavior Email with correct smtp config should be sent emails normally. ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 20:16:14 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Feb 15, 2026):

Based on similar issues reported, I found a couple of things to check with your Mailgun SMTP configuration:

1. Try enabling SMTP_OPPORTUNISTIC_TLS

For port 587, you typically need both TLS settings enabled:

SMTP_USE_TLS=true
SMTP_OPPORTUNISTIC_TLS=true

You currently have SMTP_OPPORTUNISTIC_TLS=false, but port 587 uses STARTTLS which requires opportunistic TLS to be enabled.

2. Verify MAIL_DEFAULT_SEND_FROM matches your Mailgun sender

A common cause of timeout/connection issues is when MAIL_DEFAULT_SEND_FROM doesn't match the authorized sender in your SMTP credentials. Make sure welcome@mydomain.com is an authorized sender in your Mailgun account.

3. Check the worker container logs for errors

Email errors only appear in the worker container logs:

docker logs dify-worker-1 -f --tail=100

4. Restart containers properly after config changes

After modifying .env, run:

docker compose down
docker compose up -d

(A simple restart won't pick up the new environment variables.)

Could you check the worker logs and share any error messages? That would help pinpoint the exact issue.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Feb 15, 2026): <!-- Answer --> Based on similar issues reported, I found a couple of things to check with your Mailgun SMTP configuration: **1. Try enabling `SMTP_OPPORTUNISTIC_TLS`** For port 587, you typically need both TLS settings enabled: ``` SMTP_USE_TLS=true SMTP_OPPORTUNISTIC_TLS=true ``` You currently have `SMTP_OPPORTUNISTIC_TLS=false`, but [port 587 uses STARTTLS which requires opportunistic TLS to be enabled](https://github.com/langgenius/dify/issues/14283). **2. Verify `MAIL_DEFAULT_SEND_FROM` matches your Mailgun sender** [A common cause of timeout/connection issues is when `MAIL_DEFAULT_SEND_FROM` doesn't match the authorized sender in your SMTP credentials](https://github.com/langgenius/dify/issues/20107). Make sure `welcome@mydomain.com` is an authorized sender in your Mailgun account. **3. Check the worker container logs for errors** Email errors only appear in the worker container logs: ```bash docker logs dify-worker-1 -f --tail=100 ``` **4. Restart containers properly after config changes** After modifying `.env`, run: ```bash docker compose down docker compose up -d ``` (A simple restart won't pick up the new environment variables.) Could you check the worker logs and share any error messages? That would help pinpoint the exact issue. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/c58474a7-8e6d-47a4-89f0-41469464f1e0?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/c58474a7-8e6d-47a4-89f0-41469464f1e0?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/c58474a7-8e6d-47a4-89f0-41469464f1e0?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/c58474a7-8e6d-47a4-89f0-41469464f1e0?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/c58474a7-8e6d-47a4-89f0-41469464f1e0?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/c58474a7-8e6d-47a4-89f0-41469464f1e0?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/c58474a7-8e6d-47a4-89f0-41469464f1e0?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=Based%20on%20similar%20issues%20reported%2C%20I%20found%20a%20couple%20of%20things%20to%20check%20with%20your%20Mailgun%20SMTP%20configuration%3A%0A%0A%2A%2A1.%20Try%20enabling%20%60SMTP_OPPORTUNISTIC_TLS%60%2A%2A%0A%0AFor%20port%20587%2C%20you%20typically%20need%20both%20TLS%20settings%20enabled%3A%0A%60%60%60%0ASMTP_USE_TLS%3Dtrue%0ASMTP_OPPORTUNISTIC_TLS%3Dtrue%0A%60%60%60%0A%0AYou%20currently%20have%20%60SMTP_OPPORTUNISTIC_TLS%3Dfalse%60%2C%20but%20%5Bport%20587%20uses%20STARTTLS%20which%20requires%20opportunistic%20TLS%20to%20be%20enabled%5D%28https%3A//github.com/langgenius/dify/issues/14283%29.%0A%0A%2A%2A2.%20Verify%20%60MAIL_DEFAULT_SEND_FROM%60%20matches%20your%20Mailgun%20sender%2A%2A%0A%0A%5BA%20common%20cause%20of%20timeout/connection%20issues%20is%20when%20%60MAIL_DEFAULT_SEND_FROM%60%20doesn%27t%20match%20the%20authorized%20sender%20in%20your%20SMTP%20credentials%5D%28https%3A//github.com/langgenius/dify/issues/20107%29.%20Make%20sure%20%60welcome%40mydomain.com%60%20is%20an%20authorized%20sender%20in%20your%20Mailgun%20account.%0A%0A%2A%2A3.%20Check%20the%20worker%20container%20logs%20for%20errors%2A%2A%0A%0AEmail%20errors%20only%20appear%20in%20the%20worker%20container%20logs%3A%0A%60%60%60bash%0Adocker%20logs%20dify-worker-1%20-f%20--tail%3D100%0A%60%60%60%0A%0A%2A%2A4.%20Restart%20containers%20properly%20after%20config%20changes%2A%2A%0A%0AAfter%20modifying%20%60.env%60%2C%20run%3A%0A%60%60%60bash%0Adocker%20compose%20down%0Adocker%20compose%20up%20-d%0A%60%60%60%0A%0A%28A%20simple%20restart%20won%27t%20pick%20up%20the%20new%20environment%20variables.%29%0A%0ACould%20you%20check%20the%20worker%20logs%20and%20share%20any%20error%20messages%3F%20That%20would%20help%20pinpoint%20the%20exact%20issue.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/32338)
Author
Owner

@tnfsmith commented on GitHub (Feb 15, 2026):

I try use example many config included SMTP_PORT = 465, both enable
SMTP_USE_TLS=true/false
SMTP_OPPORTUNISTIC_TLS=true/false
But nothing work at all.
Here is the log [docker-worker-1]
`
2026-02-15 14:33:04.825 INFO [Dummy-62] [mail_invite_member_task.py:29] 0b13b8bfca5c5fb9b34d22d91abb9e40 - Start send invite member mail to myemail@gmail.com in workspace MYWORKSPACE's Workspace

2026-02-15 14:33:15.174 ERROR [Dummy-62] [smtp.py:52] 0b13b8bfca5c5fb9b34d22d91abb9e40 - SMTP error occurred

Traceback (most recent call last):

File "/usr/local/lib/python3.12/smtplib.py", line 398, in getreply

line = self.file.readline(_MAXLINE + 1)

       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.12/socket.py", line 720, in readinto

return self._sock.recv_into(b)

       ^^^^^^^^^^^^^^^^^^^^^^^

File "/app/api/.venv/lib/python3.12/site-packages/gevent/_socketcommon.py", line 692, in recv_into

self._wait(self._read_event)

File "src/gevent/_hub_primitives.py", line 317, in gevent._gevent_c_hub_primitives.wait_on_socket

File "src/gevent/_hub_primitives.py", line 322, in gevent._gevent_c_hub_primitives.wait_on_socket

File "src/gevent/_hub_primitives.py", line 313, in gevent._gevent_c_hub_primitives._primitive_wait

File "src/gevent/_hub_primitives.py", line 314, in gevent._gevent_c_hub_primitives._primitive_wait

File "src/gevent/_hub_primitives.py", line 55, in gevent._gevent_c_hub_primitives.WaitOperationsGreenlet.wait

File "src/gevent/_waiter.py", line 154, in gevent._gevent_c_waiter.Waiter.get

File "src/gevent/_greenlet_primitives.py", line 65, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch

File "src/gevent/_gevent_c_greenlet_primitives.pxd", line 35, in gevent._gevent_c_greenlet_primitives._greenlet_switch

TimeoutError: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/app/api/libs/smtp.py", line 36, in send

smtp.ehlo(self.server)

File "/usr/local/lib/python3.12/smtplib.py", line 452, in ehlo

(code, msg) = self.getreply()

              ^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.12/smtplib.py", line 401, in getreply

raise SMTPServerDisconnected("Connection unexpectedly closed: "

smtplib.SMTPServerDisconnected: Connection unexpectedly closed: timed out

2026-02-15 14:33:15.176 ERROR [Dummy-62] [mail_invite_member_task.py:50] 0b13b8bfca5c5fb9b34d22d91abb9e40 - Send invite member mail to myemail@gmail.com failed

Traceback (most recent call last):

File "/usr/local/lib/python3.12/smtplib.py", line 398, in getreply

line = self.file.readline(_MAXLINE + 1)

       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.12/socket.py", line 720, in readinto

return self._sock.recv_into(b)

       ^^^^^^^^^^^^^^^^^^^^^^^

File "/app/api/.venv/lib/python3.12/site-packages/gevent/_socketcommon.py", line 692, in recv_into

self._wait(self._read_event)

File "src/gevent/_hub_primitives.py", line 317, in gevent._gevent_c_hub_primitives.wait_on_socket

File "src/gevent/_hub_primitives.py", line 322, in gevent._gevent_c_hub_primitives.wait_on_socket

File "src/gevent/_hub_primitives.py", line 313, in gevent._gevent_c_hub_primitives._primitive_wait

File "src/gevent/_hub_primitives.py", line 314, in gevent._gevent_c_hub_primitives._primitive_wait

File "src/gevent/_hub_primitives.py", line 55, in gevent._gevent_c_hub_primitives.WaitOperationsGreenlet.wait

File "src/gevent/_waiter.py", line 154, in gevent._gevent_c_waiter.Waiter.get

File "src/gevent/_greenlet_primitives.py", line 65, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch

File "src/gevent/_gevent_c_greenlet_primitives.pxd", line 35, in gevent._gevent_c_greenlet_primitives._greenlet_switch

TimeoutError: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/app/api/libs/smtp.py", line 36, in send

smtp.ehlo(self.server)

File "/usr/local/lib/python3.12/smtplib.py", line 452, in ehlo

(code, msg) = self.getreply()

              ^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.12/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 "/app/api/tasks/mail_invite_member_task.py", line 35, in send_invite_member_mail_task

email_service.send_email(

File "/app/api/libs/email_i18n.py", line 199, in send_email

self._sender.send_email(to=to, subject=email_content.subject, html_content=email_content.html_content)

File "/app/api/libs/email_i18n.py", line 154, in send_email

mail.send(to=to, subject=subject, html=html_content)

File "/app/api/extensions/ext_mail.py", line 89, in send

self._client.send(

File "/app/api/libs/smtp.py", line 62, in send

smtp.quit()

File "/usr/local/lib/python3.12/smtplib.py", line 993, in quit

res = self.docmd("quit")

      ^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.12/smtplib.py", line 431, in docmd

self.putcmd(cmd, args)

File "/usr/local/lib/python3.12/smtplib.py", line 378, in putcmd

self.send(f'{s}{CRLF}')

File "/usr/local/lib/python3.12/smtplib.py", line 365, in send

raise SMTPServerDisconnected('please run connect() first')

smtplib.SMTPServerDisconnected: please run connect() first

2026-02-15 14:33:15.212 INFO [Dummy-62] [trace.py:128] 0b13b8bfca5c5fb9b34d22d91abb9e40 - Task tasks.mail_invite_member_task.send_invite_member_mail_task[01ac4006-367f-4ab0-bf79-3e45c4f811a7] succeeded in 10.387129949987866s: None
`

@tnfsmith commented on GitHub (Feb 15, 2026): I try use example many config included SMTP_PORT = 465, both enable SMTP_USE_TLS=true/false SMTP_OPPORTUNISTIC_TLS=true/false But nothing work at all. Here is the log [docker-worker-1] ` 2026-02-15 14:33:04.825 INFO [Dummy-62] [mail_invite_member_task.py:29] 0b13b8bfca5c5fb9b34d22d91abb9e40 - Start send invite member mail to myemail@gmail.com in workspace MYWORKSPACE's Workspace 2026-02-15 14:33:15.174 ERROR [Dummy-62] [smtp.py:52] 0b13b8bfca5c5fb9b34d22d91abb9e40 - SMTP error occurred Traceback (most recent call last): File "/usr/local/lib/python3.12/smtplib.py", line 398, in getreply line = self.file.readline(_MAXLINE + 1) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/socket.py", line 720, in readinto return self._sock.recv_into(b) ^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/gevent/_socketcommon.py", line 692, in recv_into self._wait(self._read_event) File "src/gevent/_hub_primitives.py", line 317, in gevent._gevent_c_hub_primitives.wait_on_socket File "src/gevent/_hub_primitives.py", line 322, in gevent._gevent_c_hub_primitives.wait_on_socket File "src/gevent/_hub_primitives.py", line 313, in gevent._gevent_c_hub_primitives._primitive_wait File "src/gevent/_hub_primitives.py", line 314, in gevent._gevent_c_hub_primitives._primitive_wait File "src/gevent/_hub_primitives.py", line 55, in gevent._gevent_c_hub_primitives.WaitOperationsGreenlet.wait File "src/gevent/_waiter.py", line 154, in gevent._gevent_c_waiter.Waiter.get File "src/gevent/_greenlet_primitives.py", line 65, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch File "src/gevent/_gevent_c_greenlet_primitives.pxd", line 35, in gevent._gevent_c_greenlet_primitives._greenlet_switch TimeoutError: timed out During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/app/api/libs/smtp.py", line 36, in send smtp.ehlo(self.server) File "/usr/local/lib/python3.12/smtplib.py", line 452, in ehlo (code, msg) = self.getreply() ^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/smtplib.py", line 401, in getreply raise SMTPServerDisconnected("Connection unexpectedly closed: " smtplib.SMTPServerDisconnected: Connection unexpectedly closed: timed out 2026-02-15 14:33:15.176 ERROR [Dummy-62] [mail_invite_member_task.py:50] 0b13b8bfca5c5fb9b34d22d91abb9e40 - Send invite member mail to myemail@gmail.com failed Traceback (most recent call last): File "/usr/local/lib/python3.12/smtplib.py", line 398, in getreply line = self.file.readline(_MAXLINE + 1) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/socket.py", line 720, in readinto return self._sock.recv_into(b) ^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/gevent/_socketcommon.py", line 692, in recv_into self._wait(self._read_event) File "src/gevent/_hub_primitives.py", line 317, in gevent._gevent_c_hub_primitives.wait_on_socket File "src/gevent/_hub_primitives.py", line 322, in gevent._gevent_c_hub_primitives.wait_on_socket File "src/gevent/_hub_primitives.py", line 313, in gevent._gevent_c_hub_primitives._primitive_wait File "src/gevent/_hub_primitives.py", line 314, in gevent._gevent_c_hub_primitives._primitive_wait File "src/gevent/_hub_primitives.py", line 55, in gevent._gevent_c_hub_primitives.WaitOperationsGreenlet.wait File "src/gevent/_waiter.py", line 154, in gevent._gevent_c_waiter.Waiter.get File "src/gevent/_greenlet_primitives.py", line 65, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch File "src/gevent/_gevent_c_greenlet_primitives.pxd", line 35, in gevent._gevent_c_greenlet_primitives._greenlet_switch TimeoutError: timed out During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/app/api/libs/smtp.py", line 36, in send smtp.ehlo(self.server) File "/usr/local/lib/python3.12/smtplib.py", line 452, in ehlo (code, msg) = self.getreply() ^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/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 "/app/api/tasks/mail_invite_member_task.py", line 35, in send_invite_member_mail_task email_service.send_email( File "/app/api/libs/email_i18n.py", line 199, in send_email self._sender.send_email(to=to, subject=email_content.subject, html_content=email_content.html_content) File "/app/api/libs/email_i18n.py", line 154, in send_email mail.send(to=to, subject=subject, html=html_content) File "/app/api/extensions/ext_mail.py", line 89, in send self._client.send( File "/app/api/libs/smtp.py", line 62, in send smtp.quit() File "/usr/local/lib/python3.12/smtplib.py", line 993, in quit res = self.docmd("quit") ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/smtplib.py", line 431, in docmd self.putcmd(cmd, args) File "/usr/local/lib/python3.12/smtplib.py", line 378, in putcmd self.send(f'{s}{CRLF}') File "/usr/local/lib/python3.12/smtplib.py", line 365, in send raise SMTPServerDisconnected('please run connect() first') smtplib.SMTPServerDisconnected: please run connect() first 2026-02-15 14:33:15.212 INFO [Dummy-62] [trace.py:128] 0b13b8bfca5c5fb9b34d22d91abb9e40 - Task tasks.mail_invite_member_task.send_invite_member_mail_task[01ac4006-367f-4ab0-bf79-3e45c4f811a7] succeeded in 10.387129949987866s: None `
Author
Owner

@dosubot[bot] commented on GitHub (Feb 15, 2026):

The timeout at smtp.ehlo() suggests the connection is being blocked before the SMTP handshake can complete. This is a known issue in Docker deployments.

Most likely cause: SSRF Proxy blocking SMTP traffic

Dify's Docker deployment includes an SSRF proxy that blocks non-HTTP/HTTPS ports (including SMTP 587/465) by default.

Fix: Edit docker/ssrf_proxy/squid.conf.template and add or uncomment this line before any http_access deny CONNECT !SSL_ports rule:

acl SSL_ports port 1025-65535

Then restart the containers:

docker compose down
docker compose up -d

To verify the issue, test connectivity from inside the worker container:

docker exec -it dify-worker-1 sh -c 'nc -zv smtp.mailgun.org 587'

If this times out or fails, it confirms the SSRF proxy (or another network issue) is blocking the connection.

The 10-second timeout you're seeing in the logs is hardcoded in Dify's SMTP handling, so if the network connection can't be established in time, the ehlo() call fails.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Feb 15, 2026): <!-- Answer --> The timeout at `smtp.ehlo()` suggests the connection is being blocked before the SMTP handshake can complete. This is a known issue in Docker deployments. **Most likely cause: SSRF Proxy blocking SMTP traffic** [Dify's Docker deployment includes an SSRF proxy that blocks non-HTTP/HTTPS ports (including SMTP 587/465) by default](https://github.com/langgenius/dify-official-plugins/issues/1690#issuecomment-3273036284). **Fix:** Edit `docker/ssrf_proxy/squid.conf.template` and add or uncomment this line before any `http_access deny CONNECT !SSL_ports` rule: ``` acl SSL_ports port 1025-65535 ``` Then restart the containers: ```bash docker compose down docker compose up -d ``` **To verify the issue**, test connectivity from inside the worker container: ```bash docker exec -it dify-worker-1 sh -c 'nc -zv smtp.mailgun.org 587' ``` If this times out or fails, it confirms the SSRF proxy (or another network issue) is blocking the connection. [The 10-second timeout you're seeing in the logs is hardcoded in Dify's SMTP handling](https://github.com/langgenius/dify/blob/ba12960975ab4ed750bb0b7e737d96a60829f835/api/libs/smtp.py#L29-L36), so if the network connection can't be established in time, the `ehlo()` call fails. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/6bbabcc5-f09c-4d6c-8c91-1df2faf4981a?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/6bbabcc5-f09c-4d6c-8c91-1df2faf4981a?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/6bbabcc5-f09c-4d6c-8c91-1df2faf4981a?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/6bbabcc5-f09c-4d6c-8c91-1df2faf4981a?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/6bbabcc5-f09c-4d6c-8c91-1df2faf4981a?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/6bbabcc5-f09c-4d6c-8c91-1df2faf4981a?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/6bbabcc5-f09c-4d6c-8c91-1df2faf4981a?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=The%20timeout%20at%20%60smtp.ehlo%28%29%60%20suggests%20the%20connection%20is%20being%20blocked%20before%20the%20SMTP%20handshake%20can%20complete.%20This%20is%20a%20known%20issue%20in%20Docker%20deployments.%0A%0A%2A%2AMost%20likely%20cause%3A%20SSRF%20Proxy%20blocking%20SMTP%20traffic%2A%2A%0A%0A%5BDify%27s%20Docker%20deployment%20includes%20an%20SSRF%20proxy%20that%20blocks%20non-HTTP/HTTPS%20ports%20%28including%20SMTP%20587/465%29%20by%20default%5D%28https%3A//github.com/langgenius/dify-official-plugins/issues/1690%23issuecomment-3273036284%29.%0A%0A%2A%2AFix%3A%2A%2A%20Edit%20%60docker/ssrf_proxy/squid.conf.template%60%20and%20add%20or%20uncomment%20this%20line%20before%20any%20%60http_access%20deny%20CONNECT%20%21SSL_ports%60%20rule%3A%0A%60%60%60%0Aacl%20SSL_ports%20port%201025-65535%0A%60%60%60%0A%0AThen%20restart%20the%20containers%3A%0A%60%60%60bash%0Adocker%20compose%20down%0Adocker%20compose%20up%20-d%0A%60%60%60%0A%0A%2A%2ATo%20verify%20the%20issue%2A%2A%2C%20test%20connectivity%20from%20inside%20the%20worker%20container%3A%0A%60%60%60bash%0Adocker%20exec%20-it%20dify-worker-1%20sh%20-c%20%27nc%20-zv%20smtp.mailgun.org%20587%27%0A%60%60%60%0A%0AIf%20this%20times%20out%20or%20fails%2C%20it%20confirms%20the%20SSRF%20proxy%20%28or%20another%20network%20issue%29%20is%20blocking%20the%20connection.%0A%0A%5BThe%2010-second%20timeout%20you%27re%20seeing%20in%20the%20logs%20is%20hardcoded%20in%20Dify%27s%20SMTP%20handling%5D%28https%3A//github.com/langgenius/dify/blob/ba12960975ab4ed750bb0b7e737d96a60829f835/api/libs/smtp.py%23L29-L36%29%2C%20so%20if%20the%20network%20connection%20can%27t%20be%20established%20in%20time%2C%20the%20%60ehlo%28%29%60%20call%20fails.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/32338)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#22228