mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 05:40:50 +01:00
Add support for SCRAM-SHA authentication methods
Extended SMTP authentication to include SCRAM-SHA-1, SCRAM-SHA-1-PLUS, SCRAM-SHA-256, and SCRAM-SHA-256-PLUS methods. This enhancement provides more secure and flexible authentication options for SMTP clients.
This commit is contained in:
parent
e8fc6cd78f
commit
4f1a60760d
1 changed files with 29 additions and 0 deletions
29
client.go
29
client.go
|
@ -785,6 +785,35 @@ func (c *Client) auth() error {
|
||||||
return ErrXOauth2AuthNotSupported
|
return ErrXOauth2AuthNotSupported
|
||||||
}
|
}
|
||||||
c.smtpAuth = smtp.XOAuth2Auth(c.user, c.pass)
|
c.smtpAuth = smtp.XOAuth2Auth(c.user, c.pass)
|
||||||
|
case SMTPAuthSCRAMSHA1:
|
||||||
|
if !strings.Contains(smtpAuthType, string(SMTPAuthSCRAMSHA1)) {
|
||||||
|
return ErrXOauth2AuthNotSupported
|
||||||
|
}
|
||||||
|
c.smtpAuth = smtp.ScramSHA1Auth(c.user, c.pass)
|
||||||
|
case SMTPAuthSCRAMSHA1PLUS:
|
||||||
|
if !strings.Contains(smtpAuthType, string(SMTPAuthSCRAMSHA1PLUS)) {
|
||||||
|
return ErrXOauth2AuthNotSupported
|
||||||
|
}
|
||||||
|
tlsConnState, err := c.smtpClient.GetTLSConnectionState()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.smtpAuth = smtp.ScramSHA1PlusAuth(c.user, c.pass, tlsConnState)
|
||||||
|
case SMTPAuthSCRAMSHA256:
|
||||||
|
if !strings.Contains(smtpAuthType, string(SMTPAuthSCRAMSHA256)) {
|
||||||
|
return ErrXOauth2AuthNotSupported
|
||||||
|
}
|
||||||
|
c.smtpAuth = smtp.ScramSHA256Auth(c.user, c.pass)
|
||||||
|
case SMTPAuthSCRAMSHA256PLUS:
|
||||||
|
if !strings.Contains(smtpAuthType, string(SMTPAuthSCRAMSHA256PLUS)) {
|
||||||
|
return ErrXOauth2AuthNotSupported
|
||||||
|
}
|
||||||
|
tlsConnState, err := c.smtpClient.GetTLSConnectionState()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.smtpAuth = smtp.ScramSHA256PlusAuth(c.user, c.pass, tlsConnState)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unsupported SMTP AUTH type %q", c.smtpAuthType)
|
return fmt.Errorf("unsupported SMTP AUTH type %q", c.smtpAuthType)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue