@@ -132,9 +132,8 @@ func (e *EmailNotifier) Send(
132132
133133 // Set up authentication only if credentials are provided
134134 if isAuthRequired {
135- auth := smtp .PlainAuth ("" , e .SMTPUser , smtpPassword , e .SMTPHost )
136- if err := client .Auth (auth ); err != nil {
137- return fmt .Errorf ("SMTP authentication failed: %w" , err )
135+ if err := e .authenticate (client , smtpPassword ); err != nil {
136+ return err
138137 }
139138 }
140139
@@ -195,9 +194,8 @@ func (e *EmailNotifier) Send(
195194
196195 // Authenticate only if credentials are provided
197196 if isAuthRequired {
198- auth := smtp .PlainAuth ("" , e .SMTPUser , smtpPassword , e .SMTPHost )
199- if err := client .Auth (auth ); err != nil {
200- return fmt .Errorf ("SMTP authentication failed: %w" , err )
197+ if err := e .authenticate (client , smtpPassword ); err != nil {
198+ return err
201199 }
202200 }
203201
@@ -256,3 +254,19 @@ func (e *EmailNotifier) EncryptSensitiveData(encryptor encryption.FieldEncryptor
256254 }
257255 return nil
258256}
257+
258+ func (e * EmailNotifier ) authenticate (client * smtp.Client , password string ) error {
259+ // Try PLAIN auth first (most common)
260+ plainAuth := smtp .PlainAuth ("" , e .SMTPUser , password , e .SMTPHost )
261+ if err := client .Auth (plainAuth ); err == nil {
262+ return nil
263+ }
264+
265+ // If PLAIN fails, try LOGIN auth (required by Office 365 and some providers)
266+ loginAuth := & loginAuth {e .SMTPUser , password }
267+ if err := client .Auth (loginAuth ); err != nil {
268+ return fmt .Errorf ("SMTP authentication failed: %w" , err )
269+ }
270+
271+ return nil
272+ }
0 commit comments