怎么使用 aliyun (阿里云) 的邮件服务

当前服务器版本 : 13 ce 版本
部署 : docker部署
按文档修改/opt/seafile-data/seafile/conf/seahub_settings.py
阿里企业邮箱账户

  1. # -*- coding: utf-8 -*-
    SECRET_KEY = "okl#(iqax7-qr_pb3rsag163-+q1sz6oc85)6*7=dd0z(4m89g"
    
    TIME_ZONE = 'Etc/UTC'
    
    EMAIL_USE_TLS = True
    EMAIL_HOST = 'smtp.xxxxxxx.cn'        # SMTP 服务器
    EMAIL_HOST_USER = 'xxxx@xxxxxx.cn'    # 用户名和域名
    EMAIL_HOST_PASSWORD = 'xxxxxxx'       # 密码
    EMAIL_PORT = 587
    DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
    SERVER_EMAIL = EMAIL_HOST_USER
    
    

    seahub_email_sender.log 日志文件为空

测试联通是通的(我使用的是自己的smtp.xxx.com ,不是下面的smtp服务器),但是新注册用户收不到通知邮件,管理员重置密码也不能发送邮件。

       @ecs-75a5:/opt/seafile-data/seafile$ curl -v telnet://smtp.qiye.aliyun.com:587
*   Trying 59.82.14.215:587...
* Connected to smtp.qiye.aliyun.com (59.82.14.215) port 587 (#0)

seafile@ecs-75a5:/opt/seafile-data/seafile$ telnet smtp.qiye.aliyun.com 587
Trying 59.82.9.178...
Connected to smtp.qiye.aliyun.com.
Escape character is '^]'.
220 smtp.aliyun-inc.com MX AliMail Server

这个问题不解决,如果用户丢失密码,那就只能删除新建了,请求帮助,需要看什么log或者配置文件请告诉我。

  1. 文档中有提到:如果邮件服务仍无法使用,可查看日志文件 logs/seahub.log ,查找可能的错误原因。
  2. 如果邮件服务未正确配置,管理员重置密码时,重置后的密码会在页面有提示,不需要删除重建用户

补充:关闭ufw后telnet测试正常,并且连知识库的问题也解决了部分。

root@abea52b6aea1:/opt/seafile# telnet smtp.stylesourcing.cn 587
Trying 59.82.9.178...
Connected to smtp.xxxxxx.cn.
Escape character is '^]'.
220 smtp.aliyun-inc.com MX AliMail Server
Connection closed by foreign host.

seahub.log

[2025-10-24 02:27:12] [ERROR] django.request:253 log_response Internal Server Error: /api/v2.1/admin/users/573067d5bd8645a6b4c27b9078e016da@auth.loca>
Traceback (most recent call last):
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/django/views/decorators/csrf.py", line 65, in _view_wrapper
    return view_func(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/django/views/generic/base.py", line 105, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/rest_framework/views.py", line 515, in dispatch
    response = self.handle_exception(exc)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/rest_framework/views.py", line 475, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/rest_framework/views.py", line 486, in raise_uncaught_exception
    raise exc
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/rest_framework/views.py", line 512, in dispatch
    response = handler(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/seafile/seafile-server-13.0.11/seahub/seahub/api2/endpoints/admin/users.py", line 1537, in put
    send_html_email(_("Reset Password on %s") % site_name,
  File "/opt/seafile/seafile-server-13.0.11/seahub/seahub/utils/__init__.py", line 992, in send_html_email
    msg.send()
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/django/core/mail/message.py", line 307, in send
    return self.get_connection(fail_silently).send_messages([self])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/django/core/mail/backends/smtp.py", line 128, in send_messages
    new_conn_created = self.open()
                       ^^^^^^^^^^^
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/django/core/mail/backends/smtp.py", line 93, in open
    self.connection.starttls(context=self.ssl_context)
  File "/usr/lib/python3.12/smtplib.py", line 779, in starttls
    self.sock = context.wrap_socket(self.sock,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/ssl.py", line 455, in wrap_socket
    return self.sslsocket_class._create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/ssl.py", line 1042, in _create
    self.do_handshake()
  File "/usr/lib/python3.12/ssl.py", line 1320, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'smtp.style>
[2025-10-24 02:33:01] [WARNING] django.request:253 log_response Bad Request: /api/v2.1/wiki2/fdbaef1f-f8bc-4294-8892-a70863a44878/import-page/
[2025-10-24 02:33:32] [WARNING] django.request:253 log_response Not Found: /api/v2.1/query-io-status/
[2025-10-24 02:33:49] [WARNING] django.request:253 log_response Not Found: /api/v2.1/query-io-status/
[2025-10-24 02:34:12] [WARNING] django.request:253 log_response Bad Request: /api/v2.1/wiki2/fdbaef1f-f8bc-4294-8892-a70863a44878/import-page/


##下面是UFW开启时的日志

下面应该是相关logs,我刚才又重置了用户密码,没有在页面有提示.
日志显示timed out,我是应该在容器内测试下跟smtp服务器的连通么?好像容器里还没有telnet命令

seahub.log                                                                    
[2025-10-24 01:37:55] [ERROR] django.request:253 log_response Internal Server Error: /api/v2.1/admin/users/573067d5bd8645a6b4c27b9078e016da@auth.loca>
Traceback (most recent call last):
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/django/views/decorators/csrf.py", line 65, in _view_wrapper
    return view_func(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/django/views/generic/base.py", line 105, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/rest_framework/views.py", line 515, in dispatch
    response = self.handle_exception(exc)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/rest_framework/views.py", line 475, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/rest_framework/views.py", line 486, in raise_uncaught_exception
    raise exc
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/rest_framework/views.py", line 512, in dispatch
    response = handler(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/seafile/seafile-server-13.0.11/seahub/seahub/api2/endpoints/admin/users.py", line 1537, in put
    send_html_email(_("Reset Password on %s") % site_name,
  File "/opt/seafile/seafile-server-13.0.11/seahub/seahub/utils/__init__.py", line 992, in send_html_email
    msg.send()
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/django/core/mail/message.py", line 307, in send
    return self.get_connection(fail_silently).send_messages([self])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/django/core/mail/backends/smtp.py", line 128, in send_messages
    new_conn_created = self.open()
                       ^^^^^^^^^^^
  File "/opt/seafile/seafile-server-13.0.11/seahub/thirdpart/django/core/mail/backends/smtp.py", line 86, in open
    self.connection = self.connection_class(
                      ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/smtplib.py", line 255, in __init__
    (code, msg) = self.connect(host, port)
                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/smtplib.py", line 341, in connect
    self.sock = self._get_socket(host, port, self.timeout)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/smtplib.py", line 312, in _get_socket
    return socket.create_connection((host, port), timeout,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/socket.py", line 852, in create_connection
    raise exceptions[0]
  File "/usr/lib/python3.12/socket.py", line 837, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out

首先要确保smtp的连通;这里看起来应该是证书问题,服务器提供的SSL证书中列出的域名与实际连接域名不匹配

的确,使用smtp+自己域名的方式不行,必须用阿里云的公用smtp服务器地址。