aboutsummaryrefslogtreecommitdiffstats
path: root/walrss
diff options
context:
space:
mode:
authorAKP <abi@tdpain.net>2025-02-09 01:28:04 +0000
committerAKP <abi@tdpain.net>2025-02-09 01:29:09 +0000
commit1ac249268241a2eabf932e0072a62439552dd601 (patch)
treebf8761bb35fed56cd31e1b998830602a44536778 /walrss
parent948108217c2de8c233147dab8023f1548e8c2651 (diff)
Fixup email settings
Adds support for switching between STARTTLS, TLS and no TLS. Adds support for not specifying a username and password. Fixes #5
Diffstat (limited to 'walrss')
-rw-r--r--walrss/internal/rss/processor.go46
-rw-r--r--walrss/internal/state/state.go11
2 files changed, 44 insertions, 13 deletions
diff --git a/walrss/internal/rss/processor.go b/walrss/internal/rss/processor.go
index ab1b82c..ce53d5d 100644
--- a/walrss/internal/rss/processor.go
+++ b/walrss/internal/rss/processor.go
@@ -42,13 +42,13 @@ func getUserAgent(st *state.State) string {
} else if core.Version != "" {
o += "/" + core.Version
}
-
+
var parts []string
if st.Config.Platform.ContactInformation != "" {
parts = append(parts, st.Config.Platform.ContactInformation)
}
parts = append(parts, "https://github.com/codemicro/walrss")
-
+
o += " (" + strings.Join(parts, ", ") + ")"
ua.ua = o
})
@@ -370,17 +370,43 @@ func sendEmail(st *state.State, plain, html []byte, to, subject string) error {
return nil
}
- return (&email.Email{
+ e := &email.Email{
From: st.Config.Email.From,
To: []string{to},
Subject: subject,
Text: plain,
HTML: html,
- }).SendWithStartTLS(
- fmt.Sprintf("%s:%d", st.Config.Email.Host, st.Config.Email.Port),
- smtp.PlainAuth("", st.Config.Email.Username, st.Config.Email.Password, st.Config.Email.Host),
- &tls.Config{
- ServerName: st.Config.Email.Host,
- },
- )
+ }
+
+ var smtpAuth smtp.Auth
+ if st.Config.Email.Username != "" || st.Config.Email.Password != "" {
+ smtpAuth = smtp.PlainAuth("", st.Config.Email.Username, st.Config.Email.Password, st.Config.Email.Host)
+ }
+
+ smtpAddr := fmt.Sprintf("%s:%d", st.Config.Email.Host, st.Config.Email.Port)
+
+ var sendFn func(*email.Email) error
+
+ switch st.Config.Email.TLS {
+ case "no":
+ sendFn = func(e *email.Email) error {
+ return e.Send(smtpAddr, smtpAuth)
+ }
+ case "tls":
+ sendFn = func(e *email.Email) error {
+ return e.SendWithTLS(smtpAddr, smtpAuth, &tls.Config{
+ ServerName: st.Config.Email.Host,
+ })
+ }
+ case "starttls":
+ sendFn = func(e *email.Email) error {
+ return e.SendWithStartTLS(smtpAddr, smtpAuth, &tls.Config{
+ ServerName: st.Config.Email.Host,
+ })
+ }
+ default:
+ return fmt.Errorf("unknown TLS option %s", st.Config.Email.TLS)
+ }
+
+ return sendFn(e)
}
diff --git a/walrss/internal/state/state.go b/walrss/internal/state/state.go
index 5306503..522e1bf 100644
--- a/walrss/internal/state/state.go
+++ b/walrss/internal/state/state.go
@@ -23,10 +23,11 @@ func New() *State {
type Config struct {
Email struct {
Host string `fig:"host" validate:"required"`
- Username string `fig:"username" validate:"required"`
- Password string `fig:"password" validate:"required"`
- From string `fig:"from" validate:"required"`
Port int `fig:"port" validate:"required"`
+ Username string `fig:"username"`
+ Password string `fig:"password"`
+ From string `fig:"from" validate:"required"`
+ TLS string `fig:"tls" default:"starttls"`
}
Server struct {
Host string `fig:"host" default:"127.0.0.1"`
@@ -69,6 +70,10 @@ func LoadConfig() (*Config, error) {
cfg.Server.ExternalURL = strings.TrimSuffix(cfg.Server.ExternalURL, "/")
+ if cfg.Email.TLS != "tls" && cfg.Email.TLS != "starttls" && cfg.Email.TLS != "no" {
+ return nil, errors.New("invalid email.tls value: must be 'starttls', 'tls' or 'no'")
+ }
+
if !cfg.Debug {
log.Logger = log.Logger.Level(zerolog.InfoLevel)
}