mirror of
https://github.com/axllent/mailpit.git
synced 2025-06-04 23:27:32 +02:00
Code cleanup
This commit is contained in:
parent
fe5de77253
commit
628b7e7881
@ -63,22 +63,10 @@ func Send(from string, to []string, msg []byte) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var a smtp.Auth
|
auth := relayAuthFromConfig()
|
||||||
|
|
||||||
if config.SMTPRelayConfig.Auth == "plain" {
|
if auth != nil {
|
||||||
a = smtp.PlainAuth("", config.SMTPRelayConfig.Username, config.SMTPRelayConfig.Password, config.SMTPRelayConfig.Host)
|
if err = c.Auth(auth); err != nil {
|
||||||
}
|
|
||||||
|
|
||||||
if config.SMTPRelayConfig.Auth == "login" {
|
|
||||||
a = LoginAuth(config.SMTPRelayConfig.Username, config.SMTPRelayConfig.Password)
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.SMTPRelayConfig.Auth == "cram-md5" {
|
|
||||||
a = smtp.CRAMMD5Auth(config.SMTPRelayConfig.Username, config.SMTPRelayConfig.Secret)
|
|
||||||
}
|
|
||||||
|
|
||||||
if a != nil {
|
|
||||||
if err = c.Auth(a); err != nil {
|
|
||||||
return fmt.Errorf("error response to AUTH command: %s", err.Error())
|
return fmt.Errorf("error response to AUTH command: %s", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,6 +97,25 @@ func Send(from string, to []string, msg []byte) error {
|
|||||||
return c.Quit()
|
return c.Quit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the SMTP relay authentication based on config
|
||||||
|
func relayAuthFromConfig() smtp.Auth {
|
||||||
|
var a smtp.Auth
|
||||||
|
|
||||||
|
if config.SMTPRelayConfig.Auth == "plain" {
|
||||||
|
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" {
|
||||||
|
a = smtp.CRAMMD5Auth(config.SMTPRelayConfig.Username, config.SMTPRelayConfig.Secret)
|
||||||
|
}
|
||||||
|
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
// Custom implementation of LOGIN SMTP authentication
|
// Custom implementation of LOGIN SMTP authentication
|
||||||
// @see https://gist.github.com/andelf/5118732
|
// @see https://gist.github.com/andelf/5118732
|
||||||
type loginAuth struct {
|
type loginAuth struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user