]> source.dussan.org Git - gitea.git/commitdiff
Add option to use CRAM-MD5 as authentication method in the mailer
authorPeter <peter@smitmail.eu>
Thu, 18 Dec 2014 11:58:18 +0000 (13:58 +0200)
committerPeter <peter@smitmail.eu>
Thu, 18 Dec 2014 11:58:48 +0000 (13:58 +0200)
modules/mailer/mailer.go

index 6d75fa3f2c8085ac537ffe0ed3e805f6252454c2..daee5d76e8ef0b781d9daea2a4cf8f0fb6ce4241 100644 (file)
@@ -108,14 +108,21 @@ func sendMail(settings *setting.Mailer, from string, recipients []string, msgCon
                }
        }
 
-       auth_available, _ := client.Extension("AUTH")
+       auth_available, options := client.Extension("AUTH")
 
-       // Possible improvement: only plain authentication is now available.
-       // Maybe in future CRAM MD5 as well?
        if auth_available && len(settings.User) > 0 {
-               auth := smtp.PlainAuth("", settings.User, settings.Passwd, host)
-               if err = client.Auth(auth); err != nil {
-                       return err
+               var auth smtp.Auth
+
+               if strings.Contains(options, "PLAIN") {
+                       auth = smtp.PlainAuth("", settings.User, settings.Passwd, host)
+               } else if strings.Contains(options, "CRAM-MD5") {
+                       auth = smtp.CRAMMD5Auth(settings.User, settings.Passwd)
+               }
+
+               if auth != nil {
+                       if err = client.Auth(auth); err != nil {
+                               return err
+                       }
                }
        }