aboutsummaryrefslogtreecommitdiffstats
path: root/session.go
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswa Kalyan Bhuyan <[email protected]> 2025-05-24 11:03:37 +0530
committerLibravatarLibravatar Biswa Kalyan Bhuyan <[email protected]> 2025-05-24 11:25:16 +0530
commita8c6c22e7f5b629db3e6f275028a23ee9a9a50f3 (patch)
tree9106f6758856952870ab5f2b67ebe6ad97630e64 /session.go
parent85ca823eb29347726596389133ff14c8288d9185 (diff)
downloadalps-a8c6c22e7f5b629db3e6f275028a23ee9a9a50f3.tar.gz
alps-a8c6c22e7f5b629db3e6f275028a23ee9a9a50f3.tar.bz2
alps-a8c6c22e7f5b629db3e6f275028a23ee9a9a50f3.zip
Add custom SMTP authentication supportHEADmaster
- Add SMTPUsername and SMTPPassword fields to Settings struct - Update DoSMTP method to use custom credentials when available - Add SMTP credential fields to all theme templates - Support independent username/password configuration Fixes authentication issues when using different SMTP credentials than login credentials, useful for app-specific passwords.
Diffstat (limited to 'session.go')
-rw-r--r--session.go46
1 files changed, 45 insertions, 1 deletions
diff --git a/session.go b/session.go
index a85bff6..f241b6a 100644
--- a/session.go
+++ b/session.go
@@ -112,7 +112,23 @@ func (s *Session) DoSMTP(f func(*smtp.Client) error) error {
}
defer c.Close()
- auth := sasl.NewPlainClient("", s.username, s.password)
+ // Try to get custom SMTP credentials from user settings
+ smtpUsername := s.username
+ smtpPassword := s.password
+
+ // Load settings to check for custom SMTP credentials
+ if settings, err := s.loadSMTPSettings(); err == nil {
+ // Use custom username if provided, otherwise keep login username
+ if settings.SMTPUsername != "" {
+ smtpUsername = settings.SMTPUsername
+ }
+ // Use custom password if provided, otherwise keep login password
+ if settings.SMTPPassword != "" {
+ smtpPassword = settings.SMTPPassword
+ }
+ }
+
+ auth := sasl.NewPlainClient("", smtpUsername, smtpPassword)
if err := c.Auth(auth); err != nil {
return AuthError{err}
}
@@ -128,6 +144,34 @@ func (s *Session) DoSMTP(f func(*smtp.Client) error) error {
return nil
}
+// SMTPSettings represents custom SMTP authentication settings
+type SMTPSettings struct {
+ SMTPUsername string
+ SMTPPassword string
+}
+
+// loadSMTPSettings is a helper method to load SMTP settings for this session
+func (s *Session) loadSMTPSettings() (*SMTPSettings, error) {
+ const settingsKey = "base.settings"
+ var fullSettings struct {
+ MessagesPerPage int
+ Signature string
+ From string
+ Subscriptions []string
+ SMTPUsername string
+ SMTPPassword string
+ }
+
+ if err := s.Store().Get(settingsKey, &fullSettings); err != nil {
+ return nil, err
+ }
+
+ return &SMTPSettings{
+ SMTPUsername: fullSettings.SMTPUsername,
+ SMTPPassword: fullSettings.SMTPPassword,
+ }, nil
+}
+
// SetHTTPBasicAuth adds an Authorization header field to the request with
// this session's credentials.
func (s *Session) SetHTTPBasicAuth(req *http.Request) {