Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions courier/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ func NewSMTPClient(deps Dependencies, cfg *config.SMTPConfig) (*SMTPClient, erro
dialer.TLSConfig = tlsConfig
// Enforcing StartTLS
dialer.StartTLSPolicy = gomail.MandatoryStartTLS
} else {
// Set NoStartTLS to completely disable TLS negotiation when disable_starttls=true.
// This is required for development environments and SMTP servers that don't support TLS.
// Without this, the default OpportunisticStartTLS would still attempt TLS if the server
// advertises STARTTLS capability
dialer.StartTLSPolicy = gomail.NoStartTLS
}
case "smtps":
dialer.TLSConfig = tlsConfig
Expand Down
4 changes: 2 additions & 2 deletions courier/smtp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ func TestNewSMTP(t *testing.T) {
smtp = setupSMTPClient("smtps://foo:bar@my-server:1234/")
assert.Equal(t, smtp.SSL, true, "Implicit TLS should be enabled")

// Should allow cleartext => dialer.StartTLSPolicy = gomail.OpportunisticStartTLS and dialer.SSL = false
// Should disable StartTLS completely => dialer.StartTLSPolicy = gomail.NoStartTLS and dialer.SSL = false
smtp = setupSMTPClient("smtp://foo:bar@my-server:1234/?disable_starttls=true")
assert.Equal(t, smtp.StartTLSPolicy, gomail.OpportunisticStartTLS, "StartTLS is enforced")
assert.Equal(t, int(smtp.StartTLSPolicy), int(gomail.NoStartTLS), "StartTLS should be completely disabled")
assert.Equal(t, smtp.SSL, false, "Implicit TLS should not be enabled")

// Test cert based SMTP client auth
Expand Down
Loading