diff options
Diffstat (limited to 'session.go')
-rw-r--r-- | session.go | 46 |
1 files changed, 45 insertions, 1 deletions
@@ -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) { |