Skip to content

Commit

Permalink
chore(mail): set mail server hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
ncarlier committed Aug 22, 2023
1 parent 5f3e8b7 commit 4f5f327
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions pkg/helper/hostname.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package helper

import (
"os"
"strings"
)

// GetHostname returns hostname
func GetHostname() string {
hostname, _ := os.Hostname()
if hostname == "" {
hostname = "localhost"
}
return hostname
}

// GetMailHostname return mail hostname
func GetMailHostname() string {
hostname := GetHostname()
// ugly convention used in order to avoid another config params
if strings.HasPrefix(hostname, "api.") {
hostname = strings.Replace(hostname, "api", "my", 1)
}
return hostname
}
4 changes: 2 additions & 2 deletions pkg/server/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/emersion/go-smtp"
"github.com/ncarlier/readflow/pkg/config"
"github.com/ncarlier/readflow/pkg/constant"
"github.com/ncarlier/readflow/pkg/helper"
"github.com/ncarlier/readflow/pkg/mail"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -41,8 +42,7 @@ func NewSMTPHTTPServer(cfg *config.Config) *SMTPServer {
s := smtp.NewServer(backend)

s.Addr = addr
// TODO customize the domain ?
s.Domain = "localhost"
s.Domain = helper.GetMailHostname()
s.ReadTimeout = constant.DefaultTimeout
s.WriteTimeout = constant.DefaultTimeout
s.MaxMessageBytes = 1024 * 1024
Expand Down

0 comments on commit 4f5f327

Please sign in to comment.