diff --git a/app.yaml.sample b/app.yaml.sample index 0b71cbe..3c5533a 100644 --- a/app.yaml.sample +++ b/app.yaml.sample @@ -13,6 +13,7 @@ env_variables: TEMPLATE_CONTACT_REQUEST_REPLY: templates/template_reply_contact_request.html SMTP_SERVER_ADDR: "smtp.mailgun.org:587" SMTP_VERITY_CERT: true + SMTP_AUTHENTICATION_ENABLED: true SMTP_CLIENT_USERNAME: "postmaster@example.com" SMTP_CLIENT_PASSWORD: "postmasterSecretPassWord" CONTACT_REPLY_EMAIL: "noreply@example.com" diff --git a/docs/configuration-variables.md b/docs/configuration-variables.md index e242ef5..53acf33 100644 --- a/docs/configuration-variables.md +++ b/docs/configuration-variables.md @@ -4,6 +4,7 @@ Regardless of the deployment platform (Google App Engine, Kubernetes, Docker), t * `SMTP_SERVER_ADDR`: Set the address of the SMTP server in the form of `host:port`. It's required that the SMTP server being supporting TLS. * `SMTP_VERITY_CERT`: Tell whether the SMTP certificate should be validated against top level authorities. If you're using a self-signed certificate on the SMTP server, this value must be set to `false`. +* `SMTP_AUTHENTICATION_ENABLED`: Boolean (default: `true`) indicating whether SMTP authentication is required or not. If true, the variables `SMTP_CLIENT_USERNAME` and `SMTP_CLIENT_PASSWORD` are used the perform the authentication. * `SMTP_CLIENT_USERNAME`: Set the username to connect to the SMTP server. * `SMTP_CLIENT_PASSWORD`: Set the password to connect to the SMTP server. * `CONTACT_REPLY_EMAIL`: Set an email address for the reply email. It's not necessary a valid email address; for example if don't want the user to reply the email, you can set something like `noreply@example.com`. diff --git a/main.go b/main.go index 49bb8a5..f8a96e9 100644 --- a/main.go +++ b/main.go @@ -76,6 +76,7 @@ func main() { viper.SetDefault("CONTACT_REPLY_BCC_EMAIL", "contact@company.com") viper.SetDefault("EMAIL_SUBJECT", "Thanks to try our product") viper.SetDefault("DEMO_URL", "http://company.com/product-demo") + viper.SetDefault("SMTP_AUTHENTICATION_ENABLED", true) host := os.Getenv("HOST") port := os.Getenv("PORT") diff --git a/sendmail.go b/sendmail.go index 51b3622..e58c098 100644 --- a/sendmail.go +++ b/sendmail.go @@ -97,7 +97,7 @@ func (m *SendMailRequest) Execute() error { defer smtpClient.Quit() // Authenticate if configured - if viper.GetString("SMTP_CLIENT_USERNAME") != "" { + if viper.GetBool("SMTP_AUTHENTICATION_ENABLED") { smtpClientAuth := smtp.PlainAuth("", viper.GetString("SMTP_CLIENT_USERNAME"), viper.GetString("SMTP_CLIENT_PASSWORD"),