invite new member fails if SMTP server has no AUTH #13839

Closed
opened 2026-02-21 19:14:08 -05:00 by yindo · 2 comments
Owner

Originally created by @frenoid on GitHub (May 13, 2025).

Self Checks

  • 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 (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.3.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I am running Dify 1.3.1 in an OpenShift environment using the https://github.com/BorisPolonsky/dify-helm chart

I am connecting to an SMTP relay which does not support AUTH

There is a bug in your code forces SMTP auth even when SMTP_USERNAME and SMTP_PASSWORD are not set

When invoking send_invite_member_mail_task from
mail_invite_member_task.py

The mail extension forces the password to be a empty string even when the env are not set in
ext_mail.py

This forces smtp.login() to run in the class SMTPClient
smtp.py

This will throw an exception where the SMTP does not support AUTH and does not require a login

✔️ Expected Behavior

An invite_member email to be sent to my email box

Actual Behavior

No email lands in my email box

Originally created by @frenoid on GitHub (May 13, 2025). ### Self Checks - [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 (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.3.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce I am running Dify 1.3.1 in an OpenShift environment using the https://github.com/BorisPolonsky/dify-helm chart I am connecting to an SMTP relay which does not support AUTH There is a bug in your code forces SMTP auth even when SMTP_USERNAME and SMTP_PASSWORD are not set When invoking send_invite_member_mail_task from [mail_invite_member_task.py](https://github.com/langgenius/dify/blob/main/api/tasks/mail_invite_member_task.py#L13) The mail extension forces the password to be a empty string even when the env are not set in [ext_mail.py](https://github.com/langgenius/dify/blob/main/api/extensions/ext_mail.py#L52C42-L52C55) This forces smtp.login() to run in the class SMTPClient [smtp.py](https://github.com/langgenius/dify/blob/main/api/libs/smtp.py#L32) This will throw an exception where the SMTP does not support AUTH and does not require a login ### ✔️ Expected Behavior An invite_member email to be sent to my email box ### ❌ Actual Behavior No email lands in my email box
yindo added the 🐞 buggood first issue labels 2026-02-21 19:14:08 -05:00
yindo closed this issue 2026-02-21 19:14:08 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (May 13, 2025):

The issue you're experiencing is due to the logic in ext_mail.py and smtp.py, which forces SMTP authentication even when the SMTP_USERNAME and SMTP_PASSWORD environment variables are not set. In ext_mail.py, the SMTP client is initialized with empty strings for the username and password if these environment variables are not provided [1]. Consequently, the SMTPClient class in smtp.py attempts to authenticate using smtp.login() when both username and password are non-null, which includes empty strings [2].

To resolve this issue, you can modify the logic in smtp.py to check if the username and password are not empty strings before attempting to authenticate. This would prevent the smtp.login() method from being called when authentication is not required by the SMTP server.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (May 13, 2025): <!-- Answer --> The issue you're experiencing is due to the logic in `ext_mail.py` and `smtp.py`, which forces SMTP authentication even when the `SMTP_USERNAME` and `SMTP_PASSWORD` environment variables are not set. In `ext_mail.py`, the SMTP client is initialized with empty strings for the username and password if these environment variables are not provided <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/extensions/ext_mail.py)</sup>. Consequently, the `SMTPClient` class in `smtp.py` attempts to authenticate using `smtp.login()` when both username and password are non-null, which includes empty strings <sup>[[2]](https://github.com/langgenius/dify/blob/main/api/libs/smtp.py)</sup>. To resolve this issue, you can modify the logic in `smtp.py` to check if the username and password are not empty strings before attempting to authenticate. This would prevent the `smtp.login()` method from being called when authentication is not required by the SMTP server. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/b830d4c6-2fe3-4cb2-b90d-b34473f07d89?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/b830d4c6-2fe3-4cb2-b90d-b34473f07d89?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/b830d4c6-2fe3-4cb2-b90d-b34473f07d89?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/b830d4c6-2fe3-4cb2-b90d-b34473f07d89?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/b830d4c6-2fe3-4cb2-b90d-b34473f07d89?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/b830d4c6-2fe3-4cb2-b90d-b34473f07d89?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/b830d4c6-2fe3-4cb2-b90d-b34473f07d89?feedback_type=other)</sup>
Author
Owner

@AnshumanSaini commented on GitHub (Jun 1, 2025):

Hi, could you please assign this task to me?

@AnshumanSaini commented on GitHub (Jun 1, 2025): Hi, could you please assign this task to me?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#13839