High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.
JavaScript campaigncampaign-managementemail-marketingemail-subscriptionlistmonkmailing-listnewsletternewsletter-managementnewsletter-softwareself-hostedsms-gatewaysmtptransactional-emails
Add support for SMTP 'LOGIN' auth
Kailash Nadh9dcd716f9126
diff --git a/config.toml.sample b/config.toml.sampleindex 93545f0b..962c4caa 100644--- a/config.toml.sample+++ b/config.toml.sample@@ -79,7 +79,7 @@ max_idle = 10host = "my.smtp.server"port = "25"- # cram | plain | empty for no auth+ # "cram", "plain", or "login". Empty string for no auth.auth_protocol = "cram"username = "xxxxx"password = ""diff --git a/internal/messenger/emailer.go b/internal/messenger/emailer.goindex 36f12911..7e22fc8a 100644--- a/internal/messenger/emailer.go+++ b/internal/messenger/emailer.go@@ -1,6 +1,7 @@package messengerimport (+ "errors""fmt""math/rand""net/smtp"@@ -11,6 +12,12 @@ import (const emName = "email"+// loginAuth is used for enabling SMTP "LOGIN" auth.+type loginAuth struct {+ username string+ password string+}+// Server represents an SMTP server's credentials.type Server struct {Name string@@ -42,10 +49,16 @@ func NewEmailer(srv ...Server) (Messenger, error) {for _, server := range srv {s := servervar auth smtp.Auth- if s.AuthProtocol == "cram" {+ switch s.AuthProtocol {+ case "cram":auth = smtp.CRAMMD5Auth(s.Username, s.Password)- } else if s.AuthProtocol == "plain" {+ case "plain":auth = smtp.PlainAuth("", s.Username, s.Password, s.Host)+ case "login":+ auth = &loginAuth{username: s.Username, password: s.Password}+ case "":+ default:+ return nil, fmt.Errorf("unknown SMTP auth typer '%s'", s.AuthProtocol)}pool, err := email.NewPool(fmt.Sprintf("%s:%d", s.Host, s.Port), s.MaxConns, auth)@@ -115,3 +128,23 @@ func (e *emailer) Push(fromAddr string, toAddr []string, subject string, m []bytfunc (e *emailer) Flush() error {return nil}++// https://gist.github.com/andelf/5118732+// Adds support for SMTP LOGIN auth.+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, errors.New("unkown SMTP fromServer")+ }+ }+ return nil, nil+}