mirror of
https://github.com/axllent/mailpit.git
synced 2025-03-19 21:28:07 +02:00
Merge branch 'release/v1.6.13'
This commit is contained in:
commit
cd2a9d433a
@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
Notable changes to Mailpit will be documented in this file.
|
Notable changes to Mailpit will be documented in this file.
|
||||||
|
|
||||||
|
## [v1.6.13]
|
||||||
|
|
||||||
|
### Feature
|
||||||
|
- Add SMTP LOGIN authentication method for message relay
|
||||||
|
|
||||||
|
|
||||||
## [v1.6.12]
|
## [v1.6.12]
|
||||||
|
|
||||||
### Feature
|
### Feature
|
||||||
|
@ -115,11 +115,11 @@ type smtpRelayConfigStruct struct {
|
|||||||
Port int `yaml:"port"`
|
Port int `yaml:"port"`
|
||||||
STARTTLS bool `yaml:"starttls"`
|
STARTTLS bool `yaml:"starttls"`
|
||||||
AllowInsecure bool `yaml:"allow-insecure"`
|
AllowInsecure bool `yaml:"allow-insecure"`
|
||||||
Auth string `yaml:"auth"` // none, plain, cram-md5
|
Auth string `yaml:"auth"` // none, plain, login, cram-md5
|
||||||
Username string `yaml:"username"` // plain & cram-md5
|
Username string `yaml:"username"` // plain & cram-md5
|
||||||
Password string `yaml:"password"` // plain
|
Password string `yaml:"password"` // plain
|
||||||
Secret string `yaml:"secret"` // cram-md5
|
Secret string `yaml:"secret"` // cram-md5
|
||||||
ReturnPath string `yaml:"return-path"` // allows overriding the boune address
|
ReturnPath string `yaml:"return-path"` // allow overriding the bounce address
|
||||||
RecipientAllowlist string `yaml:"recipient-allowlist"` // regex, if set needs to match for mails to be relayed
|
RecipientAllowlist string `yaml:"recipient-allowlist"` // regex, if set needs to match for mails to be relayed
|
||||||
RecipientAllowlistRegexp *regexp.Regexp
|
RecipientAllowlistRegexp *regexp.Regexp
|
||||||
}
|
}
|
||||||
@ -285,6 +285,11 @@ func parseRelayConfig(c string) error {
|
|||||||
if SMTPRelayConfig.Username == "" || SMTPRelayConfig.Password == "" {
|
if SMTPRelayConfig.Username == "" || SMTPRelayConfig.Password == "" {
|
||||||
return fmt.Errorf("SMTP relay host username or password not set for PLAIN authentication (%s)", c)
|
return fmt.Errorf("SMTP relay host username or password not set for PLAIN authentication (%s)", c)
|
||||||
}
|
}
|
||||||
|
} else if SMTPRelayConfig.Auth == "login" {
|
||||||
|
SMTPRelayConfig.Auth = "login"
|
||||||
|
if SMTPRelayConfig.Username == "" || SMTPRelayConfig.Password == "" {
|
||||||
|
return fmt.Errorf("SMTP relay host username or password not set for LOGIN authentication (%s)", c)
|
||||||
|
}
|
||||||
} else if strings.HasPrefix(SMTPRelayConfig.Auth, "cram") {
|
} else if strings.HasPrefix(SMTPRelayConfig.Auth, "cram") {
|
||||||
SMTPRelayConfig.Auth = "cram-md5"
|
SMTPRelayConfig.Auth = "cram-md5"
|
||||||
if SMTPRelayConfig.Username == "" || SMTPRelayConfig.Secret == "" {
|
if SMTPRelayConfig.Username == "" || SMTPRelayConfig.Secret == "" {
|
||||||
|
@ -69,6 +69,10 @@ func Send(from string, to []string, msg []byte) error {
|
|||||||
a = smtp.PlainAuth("", config.SMTPRelayConfig.Username, config.SMTPRelayConfig.Password, config.SMTPRelayConfig.Host)
|
a = smtp.PlainAuth("", config.SMTPRelayConfig.Username, config.SMTPRelayConfig.Password, config.SMTPRelayConfig.Host)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.SMTPRelayConfig.Auth == "login" {
|
||||||
|
a = LoginAuth(config.SMTPRelayConfig.Username, config.SMTPRelayConfig.Password)
|
||||||
|
}
|
||||||
|
|
||||||
if config.SMTPRelayConfig.Auth == "cram-md5" {
|
if config.SMTPRelayConfig.Auth == "cram-md5" {
|
||||||
a = smtp.CRAMMD5Auth(config.SMTPRelayConfig.Username, config.SMTPRelayConfig.Secret)
|
a = smtp.CRAMMD5Auth(config.SMTPRelayConfig.Username, config.SMTPRelayConfig.Secret)
|
||||||
}
|
}
|
||||||
@ -103,3 +107,33 @@ func Send(from string, to []string, msg []byte) error {
|
|||||||
|
|
||||||
return c.Quit()
|
return c.Quit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Custom implementation of LOGIN SMTP authentication
|
||||||
|
// @see https://gist.github.com/andelf/5118732
|
||||||
|
type loginAuth struct {
|
||||||
|
username, password string
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoginAuth authentication
|
||||||
|
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, errors.New("Unknown fromServer")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user