list

server

This is the main dovel repository, it has the Go code to run dovel SMTP server.

curl https://dovel.email/server.tar tar

eca63cc

Author: blmayer (bleemayer@gmail.com)

Date: Thu Sep 14 21:55:38 2023 -0300

Parent: 6e42d9b

Added tls config option to server

Diff

cmd/dovel/main.go

commit eca63cc8b3dd477791f94262b29b58e0ee8247f7
Author: blmayer <bleemayer@gmail.com>
Date:   Thu Sep 14 21:55:38 2023 -0300

    Added tls config option to server

diff --git a/cmd/dovel/main.go b/cmd/dovel/main.go
index 47efe03..b99bb50 100644
--- a/cmd/dovel/main.go
+++ b/cmd/dovel/main.go
@@ -1,6 +1,7 @@
 package main
 
 import (
+	"crypto/tls"
 	"encoding/json"
 	"os"
 	"path"
@@ -41,6 +42,15 @@ func main() {
 		}
 	}
 
+	tlsCfg := &tls.Config{}
+	if cfg.Certificate != "" {
+		c, err := tls.LoadX509KeyPair(cfg.Certificate, cfg.PrivateKey)
+		if err != nil {
+			panic(err)
+		}
+		tlsCfg.Certificates = []tls.Certificate{c}
+	}
+
 	s := smtp.NewServer(backend{})
 	s.Addr = ":" + cfg.Port
 	s.Domain = cfg.Domain
@@ -49,7 +59,13 @@ func main() {
 	s.MaxMessageBytes = 1024 * 1024
 	s.MaxRecipients = 5
 
-	if err := s.ListenAndServe(); err != nil {
-		panic(err)
+	if len(tlsCfg.Certificates) > 0 {
+		s.TLSConfig = tlsCfg
+		err = s.ListenAndServeTLS()
+	} else {
+		err = s.ListenAndServe()
+	}
+	if err != nil {
+		panic(err.Error())
 	}
 }

model.go

commit eca63cc8b3dd477791f94262b29b58e0ee8247f7
Author: blmayer <bleemayer@gmail.com>
Date:   Thu Sep 14 21:55:38 2023 -0300

    Added tls config option to server

diff --git a/model.go b/model.go
index 53ad37e..5b0b3c5 100644
--- a/model.go
+++ b/model.go
@@ -10,10 +10,14 @@ import (
 // Domain is what the server should respond in a HELO or EHLO request.
 // VaultFile is the path to a json file containing the list of users
 // that can send email.
+// In order to use TLS connections Certficate and PrivateKey fields
+	// must have valid path to pem encoded keys.
 type Config struct {
-	Port      string
-	Domain    string
-	VaultFile string
+	Port        string
+	Domain      string
+	VaultFile   string
+	Certificate string
+	PrivateKey  string
 }
 
 // User represents a user that should be able to send emails. This struct is
@@ -33,4 +37,3 @@ func (w User) Login() string {
 func (w User) Pass() string {
 	return w.Password
 }
-