# 无法连接到自己的SMTP服务

**URL:** https://meta.discourse.org/t/cant-connect-to-own-smtp-service/302008
**Category:** Self-hosting
**Created:** [2024年四月2日 09:10 UTC](https://meta.discourse.org/t/cant-connect-to-own-smtp-service/302008 "2024-04-02T09:10:53Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![syntaxys](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/syntaxys/32/375406_2.png) [@syntaxys](https://meta.discourse.org/u/syntaxys)
#### Post date: [2024年四月2日 09:10 UTC](https://meta.discourse.org/t/cant-connect-to-own-smtp-service/302008/1 "2024-04-02T09:10:54Z")

</div>

我目前正在尝试为测试目的在我的家庭服务器上使用 Docker 设置 Discourse。到目前为止，它运行得相当好，实例运行得很顺利。  
但是，我无法通过我自己的服务器发送电子邮件。原则上，通过服务提供商发送是可行的。

我正在运行一个自己的 smtpd。但是，我已经禁用了通过 IPv4 发送的标准端口 465 和 587，以限制端口扫描。只有端口 23456 可用于通过 IPv4 发送。

使用以下命令进行检查：  
`root@HomeServer:/Ruby/docker.ruby.discourse# ./discourse-doctor`  
结果如下：

```plaintext
==================== MAIL TEST ====================
For a robust test, get an address from http://www.mail-tester.com/
Or just send a test message to yourself.
Email address for mail test? ('n' to skip) [hostmaster@example.com]:
Sending mail to hostmaster@example.com. . .
Testing sending to hostmaster@example.com using smtpd.example.com:23456, username:mbox_hostmaster@example.com with plain auth.
======================================== ERROR ========================================
                                    UNEXPECTED ERROR

Net::ReadTimeout

====================================== SOLUTION =======================================
This is not a common error. No recommended solution exists!

Please report the exact error message above to https://meta.discourse.org/
(And a solution, if you find one!)
=======================================================================================

```

然后我尝试通过 telnet 连接，这没有问题：

```plaintext
root@HomeServer:/Ruby/docker.ruby.discourse# docker exec -t -i 50544a79b91a /bin/bash
root@discourse:/# telnet smtpd.example.com 23456
Trying 1.2.3.4...
Connected to smtpd.example.com.
Escape character is '^]'.
quit
Connection closed by foreign host.
root@discourse:/# exit

```

app.yml 中的实际配置是：

```plaintext
DISCOURSE_SMTP_ADDRESS: smtpd.example.com
DISCOURSE_SMTP_PORT: 23456
DISCOURSE_SMTP_USER_NAME: mbox_hostmaster@example.com
DISCOURSE_SMTP_PASSWORD: pa$$word
DISCOURSE_SMTP_ENABLE_START_TLS: true # (optional, default true)
#DISCOURSE_SMTP_DOMAIN: discourse.example.com # (required by some providers)
DISCOURSE_NOTIFICATION_EMAIL: no-reply@discourse.example.com # (address to send notifications from)
# DISCOURSE_SMTP_OPENSSL_VERIFY_MODE: none
# DISCOURSE_SMTP_AUTHENTICATION: "login"

```

我也尝试通过 IPv6 来运行它，但没有成功。是否有任何解决方案可以在 docker 应用程序中启用 IPv6 连接？  
现在是 2024 年，距离该协议标准化已有 26 年，我已经用它设置了我的系统——一切运行得都非常好。

感谢您的帮助！  
Achim
