[PR #4339] fix: use smtp to send email #24490

Closed
opened 2026-02-21 20:23:06 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/4339

State: closed
Merged: No


Description

邀请用户,发送注册邮件时,邮件一直无法发出,经过本地代码测试排查,使用 smtplib 发送邮件,会卡主,同样的 SMTP 配置,使用 aiosmtplib 能正常发送。SMTP 配置的是飞书邮箱。

另外,在部署时,dify-api 在 MODE 为 api 模式时,配置以下参数是无效的,故删除:

      # Mail configuration, support: resend, smtp
      MAIL_TYPE: ''
      # default send from email address, if not specified
      MAIL_DEFAULT_SEND_FROM: 'YOUR EMAIL FROM (eg: no-reply <no-reply@dify.ai>)'
      SMTP_SERVER: ''
      SMTP_PORT: 587
      SMTP_USERNAME: ''
      SMTP_PASSWORD: ''
      SMTP_USE_TLS: 'true'
      # the api-key for resend (https://resend.com)
      RESEND_API_KEY: ''
      RESEND_API_URL: https://api.resend.com

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update, included: Dify Document
  • Improvement, including but not limited to code refactoring, performance optimization, and UI/UX improvement
  • Dependency upgrade

How Has This Been Tested?

使用 aiosmtplib 发送邮件的测试代码:

import asyncio
from email.message import EmailMessage

import aiosmtplib

message = EmailMessage()
message["From"] = "root@localhost"
message["To"] = "somebody@example.com"
message["Subject"] = "Hello World!"
message.set_content("Sent via aiosmtplib")

asyncio.run(aiosmtplib.send(message, hostname="127.0.0.1", port=25))

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
  • optional I have made corresponding changes to the documentation
  • optional I have added tests that prove my fix is effective or that my feature works
  • optional New and existing unit tests pass locally with my changes
**Original Pull Request:** https://github.com/langgenius/dify/pull/4339 **State:** closed **Merged:** No --- # Description 邀请用户,发送注册邮件时,邮件一直无法发出,经过本地代码测试排查,使用 `smtplib` 发送邮件,会卡主,同样的 SMTP 配置,使用 `aiosmtplib` 能正常发送。SMTP 配置的是飞书邮箱。 另外,在部署时,`dify-api` 在 MODE 为 `api` 模式时,配置以下参数是无效的,故删除: ``` # Mail configuration, support: resend, smtp MAIL_TYPE: '' # default send from email address, if not specified MAIL_DEFAULT_SEND_FROM: 'YOUR EMAIL FROM (eg: no-reply <no-reply@dify.ai>)' SMTP_SERVER: '' SMTP_PORT: 587 SMTP_USERNAME: '' SMTP_PASSWORD: '' SMTP_USE_TLS: 'true' # the api-key for resend (https://resend.com) RESEND_API_KEY: '' RESEND_API_URL: https://api.resend.com ``` ## Type of Change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [ ] Improvement, including but not limited to code refactoring, performance optimization, and UI/UX improvement - [ ] Dependency upgrade # How Has This Been Tested? 使用 `aiosmtplib` 发送邮件的测试代码: ``` import asyncio from email.message import EmailMessage import aiosmtplib message = EmailMessage() message["From"] = "root@localhost" message["To"] = "somebody@example.com" message["Subject"] = "Hello World!" message.set_content("Sent via aiosmtplib") asyncio.run(aiosmtplib.send(message, hostname="127.0.0.1", port=25)) ``` # Suggested Checklist: - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] My changes generate no new warnings - [ ] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods - [ ] `optional` I have made corresponding changes to the documentation - [ ] `optional` I have added tests that prove my fix is effective or that my feature works - [ ] `optional` New and existing unit tests pass locally with my changes
yindo added the pull-request label 2026-02-21 20:23:06 -05:00
yindo closed this issue 2026-02-21 20:23:06 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#24490