diff options
author | Yixin Hao <haoyixin@live.cn> | 2015-08-21 15:27:38 +0800 |
---|---|---|
committer | Yixin Hao <haoyixin@live.cn> | 2015-08-21 15:27:38 +0800 |
commit | 50cd67cd4bf9e03a555cbf44bcd76ca12a315b97 (patch) | |
tree | 55a8e7dc63ae4a8171be2874fb3f2e285b1607ee /modules/mailer/mailer.go | |
parent | 78b717f202dd989f3871fccd0bc8935fe709fac1 (diff) | |
parent | 461f715ae4699557571652d9d3baec9a4438796f (diff) |
Merge pull request #2 from gogits/develop
Update Develop
Diffstat (limited to 'modules/mailer/mailer.go')
-rw-r--r-- | modules/mailer/mailer.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go index 9dafa93f..ce3ffc27 100644 --- a/modules/mailer/mailer.go +++ b/modules/mailer/mailer.go @@ -17,6 +17,33 @@ import ( "github.com/gogits/gogs/modules/setting" ) +type loginAuth struct { + username, password string +} + +// SMTP AUTH LOGIN Auth Handler +func LoginAuth(username, password string) smtp.Auth { + return &loginAuth{username, password} +} + +func (a *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) { + return "LOGIN", []byte{}, nil +} + +func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) { + if more { + switch string(fromServer) { + case "Username:": + return []byte(a.username), nil + case "Password:": + return []byte(a.password), nil + default: + return nil, fmt.Errorf("unknwon fromServer: %s", string(fromServer)) + } + } + return nil, nil +} + type Message struct { To []string From string @@ -135,6 +162,9 @@ func sendMail(settings *setting.Mailer, recipients []string, msgContent []byte) auth = smtp.CRAMMD5Auth(settings.User, settings.Passwd) } else if strings.Contains(options, "PLAIN") { auth = smtp.PlainAuth("", settings.User, settings.Passwd, host) + } else if strings.Contains(options, "LOGIN") { + // Patch for AUTH LOGIN + auth = LoginAuth(settings.User, settings.Passwd) } if auth != nil { |