Skip to content

Fix implicit TLS (SMTPS) handling on SMTP port 465#386

Open
RobinMeis wants to merge 1 commit into
Notifuse:mainfrom
RobinMeis:main
Open

Fix implicit TLS (SMTPS) handling on SMTP port 465#386
RobinMeis wants to merge 1 commit into
Notifuse:mainfrom
RobinMeis:main

Conversation

@RobinMeis

Copy link
Copy Markdown

Fixes #385

Problem

Port 465 is implicit TLS (SMTPS): the server expects the TLS handshake immediately after the TCP connection is opened, with no plaintext greeting and no STARTTLS negotiation. The SMTP client code always configured a TLSPolicy (which only governs STARTTLS), so on port 465 it ended up waiting for a plaintext response the server would never send. The connection would hang or fail instead of succeeding.

Fix

When TLS is enabled and the port is 465, establish TLS immediately instead of relying on STARTTLS:

  • internal/service/setup_service.go (TestSMTPConnection): use mail.WithSSL() instead of mail.WithTLSPolicy(...) when UseTLS && Port == 465.
  • pkg/mailer/mailer.go (SMTPMailer.createSMTPClient): same change, using mail.WithSSL() for port 465.
  • internal/service/smtp_service.go (sendRawEmailWithSettings): wrap the raw connection with tls.Client(conn, tlsConfig) and perform the handshake right after connecting when UseTLS && Port == 465, and skip the subsequent STARTTLS command since the connection is already secured.

All other ports/configurations (STARTTLS on 587, plaintext on 25, etc.) are unaffected. The existing TLSPolicy/STARTTLS behavior is preserved.

Testing

  • Verified TestSMTPConnection and outgoing mail sending succeed against a port-465/SMTPS SMTP provider.
  • Verified STARTTLS-based providers (e.g. port 587) and unauthenticated/plaintext SMTP still work as before.

TLSPolicy only negotiates STARTTLS, which never happens on port 465
since the server expects the TLS handshake immediately. Client code
was blocking waiting for a plaintext greeting/STARTTLS response that
the server would never send. Establish TLS upfront (or use WithSSL())
when UseTLS is set and the port is 465.
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.

Bug: SMTP sending hangs / fails on port 465 (implicit TLS / SMTPS)

1 participant