diff options
| author | Bobby <[email protected]> | 2026-03-08 17:00:49 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-03-08 17:00:49 +0530 |
| commit | 2d5fb5e2078e92e7ec19582c3954409dd93f89fd (patch) | |
| tree | 932f96385d56c94596cb2bb073f0f72b13d3eee4 /utils/smtp/server.go | |
| parent | 0f254730178c9b0d9b171fef49993071a4b6a0f1 (diff) | |
| download | dove-2d5fb5e2078e92e7ec19582c3954409dd93f89fd.tar.xz dove-2d5fb5e2078e92e7ec19582c3954409dd93f89fd.zip | |
feat(dns): Implement DNS record management and query handling
- Added models for various DNS record types: A, AAAA, CNAME, MX, SRV, and TXT.
- Created repository functions for CRUD operations on DNS records.
- Developed DNS server functionality to handle incoming queries and forward them to upstream servers.
- Implemented local resolution for DNS queries, including support for A, AAAA, CNAME, MX, TXT, and SRV records.
- Enhanced SMTP server to support TLS and STARTTLS configurations.
- Improved email session handling with local delivery and error logging.
- Added new log messages for better traceability of DNS operations and SMTP actions.
Diffstat (limited to 'utils/smtp/server.go')
| -rw-r--r-- | utils/smtp/server.go | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/utils/smtp/server.go b/utils/smtp/server.go index 2773647..5260d20 100644 --- a/utils/smtp/server.go +++ b/utils/smtp/server.go @@ -1,6 +1,7 @@ package smtp import ( + "crypto/tls" "dove/config" "dove/utils/logger" "fmt" @@ -19,10 +20,26 @@ var activeServers []ServerInstance func Start() { plainAddress := fmt.Sprintf("%s:%d", config.SMTP.Host, config.SMTP.Port) plainServer := createServer(plainAddress) + activeServers = append(activeServers, ServerInstance{Server: plainServer, Label: "SMTP"}) + go startListener(plainServer, "SMTP", plainAddress) - activeServers = append(activeServers, ServerInstance{Server: plainServer, Label: LogPrefix}) + if config.SMTP.TLSEnabled { + tlsConfig := loadTLSConfig() + if tlsConfig != nil { + smtpsAddress := fmt.Sprintf("%s:%d", config.SMTP.Host, config.SMTP.SMTPSPort) + smtpsServer := createServer(smtpsAddress) + smtpsServer.TLSConfig = tlsConfig + activeServers = append(activeServers, ServerInstance{Server: smtpsServer, Label: "SMTPS"}) + go startTLSListener(smtpsServer, "SMTPS", smtpsAddress) - go startListener(plainServer, LogPrefix, plainAddress) + starttlsAddress := fmt.Sprintf("%s:%d", config.SMTP.Host, config.SMTP.StartTLSPort) + starttlsServer := createServer(starttlsAddress) + starttlsServer.TLSConfig = tlsConfig + starttlsServer.EnableSMTPUTF8 = true + activeServers = append(activeServers, ServerInstance{Server: starttlsServer, Label: "STARTTLS"}) + go startListener(starttlsServer, "STARTTLS", starttlsAddress) + } + } } func Shutdown() { @@ -51,6 +68,18 @@ func createServer(address string) *gosmtp.Server { return smtpServer } +func loadTLSConfig() *tls.Config { + certificate, loadError := tls.LoadX509KeyPair(config.SMTP.TLSCertPath, config.SMTP.TLSKeyPath) + if loadError != nil { + logger.Errorf(LogPrefix, TLSCertLoadFailed, loadError) + return nil + } + + return &tls.Config{ + Certificates: []tls.Certificate{certificate}, + } +} + func startListener(smtpServer *gosmtp.Server, label string, address string) { logger.Successf(LogPrefix, ServerStarting, label, address) @@ -58,3 +87,11 @@ func startListener(smtpServer *gosmtp.Server, label string, address string) { logger.Fatalf(LogPrefix, ListenFailed, label, listenError) } } + +func startTLSListener(smtpServer *gosmtp.Server, label string, address string) { + logger.Successf(LogPrefix, ServerStarting, label, address) + + if listenError := smtpServer.ListenAndServeTLS(); listenError != nil { + logger.Fatalf(LogPrefix, ListenFailed, label, listenError) + } +} |
