Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Commit

Permalink
Added settings for implicit TLS support
Browse files Browse the repository at this point in the history
  • Loading branch information
MFAshby committed Feb 15, 2020
1 parent 745023c commit 27f7cdd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
12 changes: 8 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ const (
ServerName = "ServerName"

// Ports / addresses to listen on for various services
MsaAddress = "MsaAddress"
MtaAddress = "MtaAddress"
ImapAddress = "ImapAddress"
WebAdminAddress = "WebAdminAddress"
MsaAddress = "MsaAddress"
MsaImplicitTLSAddress = "MsaImplicitTLSAddress"
MtaAddress = "MtaAddress"
ImapAddress = "ImapAddress"
ImapImplicitTLSAddress = "ImapImplicitTLSAddress"
WebAdminAddress = "WebAdminAddress"

// DNS
DnsServer = "DnsServer"
Expand Down Expand Up @@ -85,8 +87,10 @@ func SetupConfig() {
viper.SetDefault(ServerName, "mail.example.com")

viper.SetDefault(MsaAddress, ":587")
viper.SetDefault(MsaImplicitTLSAddress, ":465")
viper.SetDefault(MtaAddress, ":25")
viper.SetDefault(ImapAddress, ":143")
viper.SetDefault(ImapImplicitTLSAddress, ":993")
viper.SetDefault(WebAdminAddress, ":443")
viper.SetDefault(WebAdminUseTls, true)

Expand Down
14 changes: 14 additions & 0 deletions imap/imap_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ func StartImap(db *sql.DB, tls *tls.Config) {
log.Fatal(err)
}
}()

// Also start one on the
if config.GetBool(config.ImapUseTls) {
s := server.New(be)
s.Addr = config.GetString(config.ImapImplicitTLSAddress)
s.Debug = os.Stdout
s.TLSConfig = tls
go func() {
log.Println("Starting IMAP server with implicit TLS at ", s.Addr)
if err := s.ListenAndServeTLS(); err != nil {
log.Fatal(err)
}
}()
}
}

type imapBackend struct {
Expand Down
20 changes: 20 additions & 0 deletions smtp/mail_submission_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ func StartMsa(db *sql.DB, proc process.MsgProcessor, tls *tls.Config) {
log.Fatal(err)
}
}()

// Also start one on the implicit TLS port if we're using TLS
if config.GetBool(config.MsaUseTls) {
s := smtp.NewServer(be)
s.Addr = config.GetString(config.MsaImplicitTLSAddress)
s.Domain = config.GetString(config.ServerName)
//TODO come back to this
// s.ReadTimeout = time.Duration config.GetInt(config.MaxIdleSeconds)
s.MaxMessageBytes = config.GetInt(config.MaxMessageBytes)
s.MaxRecipients = config.GetInt(config.MaxRecipients)
s.AllowInsecureAuth = !config.GetBool(config.MsaUseTls)
s.Debug = os.Stdout
s.TLSConfig = tls
go func() {
log.Println("Starting mail submission agent with implicit TLS at ", s.Addr)
if err := s.ListenAndServeTLS(); err != nil {
log.Fatal(err)
}
}()
}
}

type smtpSubmissionBackend struct {
Expand Down

0 comments on commit 27f7cdd

Please sign in to comment.