-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use smtp to send email #4339
Conversation
aiosmtplib is the asynchronous version of smtplib, but Dify's current flask/celery doesn't support asynchronous. |
已经知道问题所在了,如果 SMTP 服务器使用 SSL,使用 |
I was able to reproduce this issue with an Implicit TLS server on port 465. Changing the SMTP initialization to the following code resolved the problem: if self._use_tls:
smtp = smtplib.SMTP_SSL(self.server, self.port, timeout=10)
else:
smtp = smtplib.SMTP(self.server, self.port, timeout=10) However, this might cause issues for Explicit TLS servers using port 587. To address this, we may need an additional flag to distinguish between these scenarios. Since custom ports can be used, it's not always clear whether the connection should use STARTTLS or Implicit TLS. |
self.server = server | ||
self.port = port | ||
self.port = int(port) | ||
self._from = _from | ||
self.username = username | ||
self.password = password |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the assignment of self._use_tls
is missing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._use_tls = use_tls
is after self.password = password
, no changed
@takatost Do you have any thoughts on how to distinguish between Explicit and Implicit TLS? Implementing current fixes may cause issues for Explicit TLS servers, as they require STARTTLS implementation. However, Explicit TLS is deprecated and potentially insecure, so Dify might consider not supporting it at all. |
Description
邀请用户,发送注册邮件时,邮件一直无法发出,经过本地代码测试排查,使用
smtplib
发送邮件,会卡主,同样的 SMTP 配置,使用aiosmtplib
能正常发送。SMTP 配置的是飞书邮箱。另外,在部署时,
dify-api
在 MODE 为api
模式时,配置以下参数是无效的,故删除:Type of Change
How Has This Been Tested?
使用
aiosmtplib
发送邮件的测试代码:Suggested Checklist:
dev/reformat
(backend) andcd web && npx lint-staged
(frontend) to appease the lint godsoptional
I have made corresponding changes to the documentationoptional
I have added tests that prove my fix is effective or that my feature worksoptional
New and existing unit tests pass locally with my changes