没有不值得去解决的问题,也没有不值得去学习的技术!

Thunderbird Cannot Send Gmail After Setting Up a Self-Hosted VPN: Causes and Solutions

[Screenshot 5: Clash rule snippet, highlighting the two newly added DST-PORT rules]

1. Problem Description

While using my self-hosted VPN setup (Wstunnel + WireGuard + Clash Verge Rev), I found that Thunderbird could not send emails via Gmail, producing the following errors:

  • “Unable to connect to outgoing server (SMTP) smtp.gmail.com. The server may be unavailable or refusing SMTP connections.”
  • Or: “The message could not be sent because the connection to the outgoing server (SMTP) smtp.gmail.com timed out.”

Meanwhile, accessing https://mail.google.com through the browser worked perfectly. This indicates that the VPN itself can reach Google, and the issue lies in Thunderbird’s traffic not being proxied correctly.

[Screenshot 1: Thunderbird send failure error popup]

[Screenshot 1: Thunderbird send failure error popup]

2. Root Cause Analysis

The core reason is that Clash routing rules do not cover email protocol ports.

  • My VPN setup uses Clash for traffic routing, and the default rules typically only cover common HTTP/HTTPS ports (80, 443).
  • Thunderbird uses the SMTP protocol to send emails, operating on port 587 or 465. Because the rules do not explicitly match these ports, Clash routes the traffic to DIRECT (direct connection).
  • However, my network environment requires a VPN to access the external internet. A direct connection cannot reach Google’s SMTP servers, resulting in a timeout or refused connection.

The browser can access Gmail because web traffic uses port 443, which is caught by the MATCH,Proxy fallback rule in Clash. This creates the situation where “the web interface works, but the email client fails.”

3. Solution

3.1 Verify Thunderbird’s SMTP Settings

First, ensure that Thunderbird’s outgoing server configuration meets Gmail’s requirements, especially OAuth2 authentication (Google has phased out standard password authentication).

Go to Thunderbird’s Account Settings → Outgoing Server (SMTP), and edit the corresponding Gmail outgoing server.

[Screenshot 2: Edit outgoing server window, showing port 465 + SSL/TLS + OAuth2]

[Screenshot 2: Edit outgoing server window, showing port 465 + SSL/TLS + OAuth2]

[Screenshot 3: Edit outgoing server window, showing port 587 + STARTTLS + OAuth2] (Final recommended configuration)


[Screenshot 3: Edit outgoing server window, showing port 587 + STARTTLS + OAuth2] (Final recommended configuration)

The following parameters are recommended:

ItemValue
Server Addresssmtp.gmail.com
Port587
Connection SecuritySTARTTLS
Authentication MethodOAuth2
UsernameFull Gmail address

Save the settings, restart Thunderbird, and try sending a test email. If it still fails, proceed to the next step.

[Screenshot 4: Thunderbird send failure error popup]

[Screenshot 4: Thunderbird send failure error popup]

3.2 Modify Clash Configuration to Add Email Port Proxy Rules

Open the Clash configuration file (I used the custom rules in my Clash Verge Rev subscription file), locate the rules: field, and insert the following two lines after the local LAN direct connection rules and before the domestic traffic direct connection rules:

YAML
rules:
  # ... 前面的规则 ...

  # 本地局域网直连
  - IP-CIDR,127.0.0.1/8,DIRECT
  - IP-CIDR,10.0.0.0/8,DIRECT
  - IP-CIDR,172.16.0.0/12,DIRECT
  - IP-CIDR,192.168.0.0/16,DIRECT

  # ===== 新增:邮件端口走代理 =====
  - DST-PORT,587,Proxy
  - DST-PORT,465,Proxy

  # 国内流量直连
  - DOMAIN-SUFFIX,cn,DIRECT
  - GEOIP,CN,DIRECT

  # 其他全部走代理
  - MATCH,Proxy

Note: Proxy should be replaced with the actual proxy policy group name used in your configuration (e.g., PROXY, ZgoCloud-WG, etc.).

[Screenshot 5: Clash rule snippet, highlighting the two newly added DST-PORT rules]

[Screenshot 5: Clash rule snippet, highlighting the two newly added DST-PORT rules]

Save the configuration file, then reload the configuration in Clash Verge Rev (click the refresh icon on the Profiles page, or restart Clash).

3.3 Verify the Result

Restart Thunderbird and try sending the email again. After following the steps above, the email should send successfully.

4. Alternative Troubleshooting Methods

If it still times out after making the changes, try the following two methods:

4.1 Configure a SOCKS5 Proxy Directly in Thunderbird

Bypass Clash’s rule-based routing and force all Thunderbird traffic through the proxy.

  • Open Thunderbird Settings → General → Network Settings at the bottom → Settings…
  • Select Manual proxy configuration
  • SOCKS Host: 127.0.0.1, Port: Clash’s SOCKS5 port (usually 7897)
  • Check Proxy DNS when using SOCKS v5
  • Click OK and restart Thunderbird.

If this method works, it means Wstunnel and WireGuard are fine, and the issue lies solely with the Clash rules. In this case, check if the rule order or policy group name is correct. I previously had a setup where I manually configured the proxy; for reference: Ubuntu 26.04 Email Client Troubleshooting: From NetEase Mail Master to Thunderbird, Adding 8 Mailboxes in One Go

4.2 Check Wstunnel’s Port Forwarding Scope

Some Wstunnel startup commands only specify forwarding for the WireGuard port (e.g., 51820), preventing other ports (e.g., 587, 465) from reaching the remote server.

Verify whether your Wstunnel startup parameters restrict port forwarding. Typically, the default configuration forwards all TCP ports. If necessary, modify the Wstunnel startup command to remove the port restriction.

5. Summary

The root cause of this issue is that Clash routing rules did not include email ports, causing Thunderbird’s SMTP traffic to use a direct connection. The solution is straightforward: add the following to the rules section of the Clash rules:

YAML
- DST-PORT,587,Proxy
- DST-PORT,465,Proxy

This approach also applies to proxy issues with other non-HTTP protocols (such as SSH, gaming, app store updates, etc.)—simply find the corresponding port and add it to the proxy rules.


Environment Reference: Ubuntu 26.04 + Thunderbird 151.0.1 + Clash Verge Rev + Self-hosted Wstunnel/WireGuard Setup.

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系