Allow unauthenticated SMTP
This commit is contained in:
parent
9e7fbaa445
commit
468de54746
15
sendmail.go
15
sendmail.go
|
@ -75,10 +75,6 @@ func (m *SendMailRequest) Execute() error {
|
||||||
// Connect to the SMTP Server
|
// Connect to the SMTP Server
|
||||||
smtpServerAddr := viper.GetString("SMTP_SERVER_ADDR")
|
smtpServerAddr := viper.GetString("SMTP_SERVER_ADDR")
|
||||||
smtpServerHost, _, _ := net.SplitHostPort(smtpServerAddr)
|
smtpServerHost, _, _ := net.SplitHostPort(smtpServerAddr)
|
||||||
smtpClientAuth := smtp.PlainAuth("",
|
|
||||||
viper.GetString("SMTP_CLIENT_USERNAME"),
|
|
||||||
viper.GetString("SMTP_CLIENT_PASSWORD"),
|
|
||||||
smtpServerHost)
|
|
||||||
|
|
||||||
// TLS config
|
// TLS config
|
||||||
tlsconfig := &tls.Config{
|
tlsconfig := &tls.Config{
|
||||||
|
@ -100,8 +96,15 @@ func (m *SendMailRequest) Execute() error {
|
||||||
}
|
}
|
||||||
defer smtpClient.Quit()
|
defer smtpClient.Quit()
|
||||||
|
|
||||||
if err = smtpClient.Auth(smtpClientAuth); err != nil {
|
// Authenticate if configured
|
||||||
return fmt.Errorf("failed authenticating to smtp server (%s)", err)
|
if viper.GetString("SMTP_CLIENT_USERNAME") != "" {
|
||||||
|
smtpClientAuth := smtp.PlainAuth("",
|
||||||
|
viper.GetString("SMTP_CLIENT_USERNAME"),
|
||||||
|
viper.GetString("SMTP_CLIENT_PASSWORD"),
|
||||||
|
smtpServerHost)
|
||||||
|
if err = smtpClient.Auth(smtpClientAuth); err != nil {
|
||||||
|
return fmt.Errorf("failed authenticating to smtp server (%s)", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize a mail transaction
|
// Initialize a mail transaction
|
||||||
|
|
Loading…
Reference in New Issue