Skip to content

Commit

Permalink
Updated config format for operator
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Feb 3, 2024
1 parent 7806c35 commit c534744
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ jobs:
push: true
tags: |
ghcr.io/scheiblingco/smtp-relay:latest
ghcr.io/scheiblingco/smtp-relay:0.6.1
ghcr.io/scheiblingco/smtp-relay:0.7.1
docker.io/scheibling/smtp-relay:latest
docker.io/scheibling/smtp-relay:0.6.1
docker.io/scheibling/smtp-relay:0.7.1
32 changes: 16 additions & 16 deletions config.example.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
{
"server": {
"host": "smtp.example.com",
"listen": ":2525",
"listen": 2525,
"smtps": true,
"listenSmtps": ":4650",
"listenSmtps": 4650,
"startTls": true,
"tlsCert": "tls.crt",
"tlsKey": "tls.key",
"allowInsecure": true,
"readTimeout": 10,
"writeTimeout": 10,
"maxRecipients": 100,
"maxMessageSizeMb": 30,
"credentials": {
"all": {
"password": "all",
"allowedDomains": []
},
"specific": {
"password": "specific",
"allowedDomains": [
"example.com"
]
}
}
"maxMessageSizeMb": 30
},
"remote": {
"host": "mail.provider.com",
"port": "25",
"port": 25,
"startTls": true,
"username": "",
"password": "",
"authPlain": false,
"authLogin": false
},
"credentials": {
"all": {
"password": "all",
"allowedDomains": []
},
"specific": {
"password": "specific",
"allowedDomains": [
"example.com"
]
}
}
}
40 changes: 20 additions & 20 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,23 @@ type Credential struct {
}

type ServerConfig struct {
Host string `json:"host" default:"localhost"`
Listen string `json:"listen" default:":2525"`
StartTLS bool `json:"startTls" default:"false"`
SMTPS bool `json:"smtps" default:"false"`
ListenSMTPS string `json:"listenSmtps" default:":4650"`
TLSCert string `json:"tlsCert" default:""`
TLSKey string `json:"tlsKey" default:""`
AllowInsecure bool `json:"allowInsecure" default:"true"`
ReadTimeout time.Duration `json:"readTimeout" default:"10"`
WriteTimeout time.Duration `json:"writeTimeout" default:"10"`
MaxRecipients int `json:"maxRecipients" default:"50"`
MaxMessageSizeMb int `json:"maxMessageSizeMb" default:"30"`
Credentials map[string]Credential `json:"credentials"`
Host string `json:"host" default:"localhost"`
Listen int `json:"listen" default:"2525"`
StartTLS bool `json:"startTls" default:"false"`
SMTPS bool `json:"smtps" default:"false"`
ListenSMTPS int `json:"listenSmtps" default:"4650"`
TLSCert string `json:"tlsCert" default:""`
TLSKey string `json:"tlsKey" default:""`
AllowInsecure bool `json:"allowInsecure" default:"true"`
ReadTimeout time.Duration `json:"readTimeout" default:"10"`
WriteTimeout time.Duration `json:"writeTimeout" default:"10"`
MaxRecipients int `json:"maxRecipients" default:"50"`
MaxMessageSizeMb int `json:"maxMessageSizeMb" default:"30"`
}

type RemoteConfig struct {
Host string `json:"host" default:"localhost"`
Port string `json:"port" default:"2525"`
Port int `json:"port" default:"2525"`
StartTls bool `json:"startTls" default:"false"`
AuthPlain bool `json:"authPlain" default:"false"`
AuthLogin bool `json:"authLogin" default:"false"`
Expand All @@ -50,8 +49,9 @@ type RemoteConfig struct {
}

type Config struct {
Server ServerConfig `json:"server"`
Remote RemoteConfig `json:"remote"`
Server ServerConfig `json:"server"`
Remote RemoteConfig `json:"remote"`
Credentials map[string]Credential `json:"credentials"`
}

// The Backend implements SMTP server methods.
Expand Down Expand Up @@ -82,7 +82,7 @@ type Session struct {
}

func (s *Session) SendMail() error {
c, err := smtp.Dial(remote.Config.Host + ":" + remote.Config.Port)
c, err := smtp.Dial(remote.Config.Host + ":" + string(remote.Config.Port))
if err != nil {
return err
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func (s *Session) SendMail() error {
}

func (s *Session) AuthPlain(username, password string) error {
val, ok := config.Server.Credentials[username]
val, ok := config.Credentials[username]

if ok && val.Password == password {
log.Println("User", username, "authenticated successfully")
Expand Down Expand Up @@ -263,7 +263,7 @@ func main() {
}
}

smtps.Addr = config.Server.Listen
smtps.Addr = ":" + fmt.Sprint(config.Server.Listen)
smtps.Domain = config.Server.Host
smtps.ReadTimeout = config.Server.ReadTimeout * time.Second
smtps.WriteTimeout = config.Server.WriteTimeout * time.Second
Expand All @@ -288,7 +288,7 @@ func main() {

if config.Server.SMTPS {
smtpss = smtp.NewServer(be)
smtpss.Addr = config.Server.ListenSMTPS
smtpss.Addr = ":" + fmt.Sprint(config.Server.ListenSMTPS)
smtpss.Domain = config.Server.Host
smtpss.ReadTimeout = config.Server.ReadTimeout * time.Second
smtpss.WriteTimeout = config.Server.WriteTimeout * time.Second
Expand Down

0 comments on commit c534744

Please sign in to comment.