Skip to content

Add support for **Implicit TLS (SMTPS)** to the SMTP email service#1554

Open
hungtcs wants to merge 1 commit into
getfider:mainfrom
hungtcs:main
Open

Add support for **Implicit TLS (SMTPS)** to the SMTP email service#1554
hungtcs wants to merge 1 commit into
getfider:mainfrom
hungtcs:main

Conversation

@hungtcs
Copy link
Copy Markdown

@hungtcs hungtcs commented May 27, 2026

The SMTP Send function only supported STARTTLS (plain connection → STARTTLS command → TLS upgrade), which works on ports like 587.
However, many SMTP servers — including Aliyun DirectMail — use port 465 with Implicit TLS (TLS handshake before any SMTP command).
The original code attempted a plain TCP connection on port 465, causing the server to reject it immediately with EOF.

Changes

app/pkg/env/env.go

  • Added new config field EMAIL_SMTP_ENABLE_IMPLICIT_TLS (default: false)

app/services/email/smtp/smtp.go

  • Send function now accepts an enableImplicitTLS bool parameter
  • When enabled, establishes a TLS connection (tls.Dial) before any SMTP dialogue, then creates the SMTP client via smtp.NewClient
  • When disabled, falls back to the original smtp.Dial + STARTTLS flow
  • STARTTLS is automatically skipped when implicit TLS is active

app/services/email/smtp/smtp_test.go

  • Updated mockSend signature to match the new Send function signature

Usage

Add to .env:

EMAIL_SMTP_HOST=smtp.example.com
EMAIL_SMTP_PORT=465
EMAIL_SMTP_ENABLE_STARTTLS=false
EMAIL_SMTP_ENABLE_IMPLICIT_TLS=true

- Add EMAIL_SMTP_ENABLE_IMPLICIT_TLS config variable to replace hardcoded port check
- Send function now uses the config flag to establish TLS before any SMTP command
- Skip STARTTLS when implicit TLS is active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant