Skip to content

SMTP: Add fallback from TLS to STARTTLS when both are enabled #2

@Oak-V

Description

@Oak-V

Hello @visionik,

Context

While testing IMAP and SMTP with iCloud.com email accounts, I noticed a difference in behavior between the two protocols.

IMAP works out of the box without any additional configuration. However, SMTP fails when the client attempts to establish a connection using DialTLS.

The failure occurs at:

internal/smtp/client.go:218

At this point, the code attempts a direct TLS connection, which triggers an error flow. In contrast, when using STARTTLS, the connection to the iCloud.com SMTP server succeeds and email delivery works as expected.

Analysis

This behavior suggests that, for iCloud.com, direct TLS SMTP connections are not consistently supported in the same way as STARTTLS. While both are valid SMTP security mechanisms, they are not interchangeable in practice across all providers.

Proposal

Add support for a fallback mechanism when both TLS and STARTTLS are enabled in the configuration.

Example:

{
  "accounts": {
    "someone@icloud.com": {
      "smtp": {
        "tls": true,
        "starttls": true
      }
    }
  }
}

Proposed behavior:

  1. Attempt a direct TLS connection (DialTLS)
  2. If it fails, automatically fall back to STARTTLS

Question

Are there any architectural or design constraints in the project that would prevent or discourage implementing this fallback strategy? If not, I can open a PR implementing this behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions