diff --git a/email/engine.go b/email/engine.go index a061efa..a4d2dad 100644 --- a/email/engine.go +++ b/email/engine.go @@ -45,7 +45,7 @@ func ToHTML(mdtext string) (template.HTML, error) { } func Parse(b *Body) (string, error) { - b.App = app + merge(&b.App) buf := &bytes.Buffer{} err := engine.Execute(buf, b) if err != nil { @@ -58,3 +58,21 @@ func Parse(b *Body) (string, error) { html, err := pre.Transform() return html, err } + +func merge(base *App) { + if base.Name == "" { + base.Name = app.Name + } + if base.Link == "" { + base.Link = app.Link + } + if base.Logo == "" { + base.Logo = app.Logo + } + if base.Copyright == "" { + base.Copyright = app.Copyright + } + if base.TroubleText == "" { + base.TroubleText = app.TroubleText + } +} diff --git a/email/service.go b/email/service.go index fd12841..cef0150 100644 --- a/email/service.go +++ b/email/service.go @@ -22,13 +22,17 @@ func (srv *Service) Init() error { app.Link = viper.GetString("server.url") app.Logo = viper.GetString("logo") - dial = gomail.NewDialer( + dial = DefaultDailer() + + return nil +} + +func DefaultDailer() *gomail.Dialer { + return gomail.NewDialer( viper.GetString("email.host"), viper.GetInt("email.port"), viper.GetString("email.username"), viper.GetString("email.password")) - - return nil } func setupDefault() { @@ -40,3 +44,11 @@ func setupDefault() { app.TroubleText = "If you’re having trouble with the button '{ACTION}', copy and paste the URL below into your web browser." dial = gomail.NewDialer("mail.kumoly.io", 587, "test@kumoly.io", "test") } + +func SetDefault(a App) { + app = a +} + +func SetDailer(d *gomail.Dialer) { + dial = d +}