Allow unauthenticated SMTP
This commit is contained in:
parent
9e7fbaa445
commit
468de54746
11
sendmail.go
11
sendmail.go
|
@ -75,10 +75,6 @@ func (m *SendMailRequest) Execute() error {
|
|||
// Connect to the SMTP Server
|
||||
smtpServerAddr := viper.GetString("SMTP_SERVER_ADDR")
|
||||
smtpServerHost, _, _ := net.SplitHostPort(smtpServerAddr)
|
||||
smtpClientAuth := smtp.PlainAuth("",
|
||||
viper.GetString("SMTP_CLIENT_USERNAME"),
|
||||
viper.GetString("SMTP_CLIENT_PASSWORD"),
|
||||
smtpServerHost)
|
||||
|
||||
// TLS config
|
||||
tlsconfig := &tls.Config{
|
||||
|
@ -100,9 +96,16 @@ func (m *SendMailRequest) Execute() error {
|
|||
}
|
||||
defer smtpClient.Quit()
|
||||
|
||||
// Authenticate if configured
|
||||
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
|
||||
err = smtpClient.Mail(m.from)
|
||||
|
|
Loading…
Reference in New Issue