summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlos Tadeu Panato Junior <ctadeu@gmail.com>2017-05-09 15:34:30 +0200
committerHarrison Healey <harrisonmhealey@gmail.com>2017-05-09 09:34:30 -0400
commit0df61d161f98183069494cc349d18f01d8783453 (patch)
treebc98e6767c32b97cd45d860c1469a91062da2a3a
parent622998add12734a6c2b5d79918338a4d6dca7ce6 (diff)
downloadchat-0df61d161f98183069494cc349d18f01d8783453.tar.gz
chat-0df61d161f98183069494cc349d18f01d8783453.tar.bz2
chat-0df61d161f98183069494cc349d18f01d8783453.zip
implement PLT-6469 - Send HELO request containing domain name to SMTP server (#6322)
-rw-r--r--i18n/en.json8
-rw-r--r--utils/mail.go10
-rw-r--r--utils/utils.go9
3 files changed, 27 insertions, 0 deletions
diff --git a/i18n/en.json b/i18n/en.json
index 4c8a80507..3aaabc686 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -5903,6 +5903,10 @@
"id": "utils.mail.connect_smtp.open_tls.app_error",
"translation": "Failed to open TLS connection"
},
+ {
+ "id": "utils.mail.connect_smtp.helo.app_error",
+ "translation": "Failed to set HELO"
+ },
{
"id": "utils.mail.new_client.auth.app_error",
"translation": "Failed to authenticate on SMTP server"
@@ -5912,6 +5916,10 @@
"translation": "Failed to open a connection to SMTP server %v"
},
{
+ "id": "utils.mail.new_client.helo.error",
+ "translation": "Failed to to set the HELO to SMTP server %v"
+ },
+ {
"id": "utils.mail.send_mail.close.app_error",
"translation": "Failed to close connection to SMTP server"
},
diff --git a/utils/mail.go b/utils/mail.go
index ea62fab12..bfa8f208a 100644
--- a/utils/mail.go
+++ b/utils/mail.go
@@ -49,6 +49,7 @@ func newSMTPClient(conn net.Conn, config *model.Config) (*smtp.Client, *model.Ap
l4g.Error(T("utils.mail.new_client.open.error"), err)
return nil, model.NewLocAppError("SendMail", "utils.mail.connect_smtp.open_tls.app_error", nil, err.Error())
}
+
auth := smtp.PlainAuth("", config.EmailSettings.SMTPUsername, config.EmailSettings.SMTPPassword, config.EmailSettings.SMTPServer+":"+config.EmailSettings.SMTPPort)
if config.EmailSettings.ConnectionSecurity == model.CONN_SECURITY_TLS {
if err = c.Auth(auth); err != nil {
@@ -135,6 +136,15 @@ func SendMailUsingConfig(to, subject, body string, config *model.Config) *model.
defer c.Quit()
defer c.Close()
+ siteName := GetSiteName(*config.ServiceSettings.SiteURL)
+ if siteName != "" {
+ err := c.Hello(siteName)
+ if err != nil {
+ l4g.Error(T("utils.mail.new_client.helo.error"), err)
+ return model.NewLocAppError("SendMail", "utils.mail.connect_smtp.helo.app_error", nil, err.Error())
+ }
+ }
+
if err := c.Mail(fromMail.Address); err != nil {
return model.NewLocAppError("SendMail", "utils.mail.send_mail.from_address.app_error", nil, err.Error())
}
diff --git a/utils/utils.go b/utils/utils.go
index f34c82f24..038f6ab61 100644
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -6,6 +6,7 @@ package utils
import (
"net"
"net/http"
+ "net/url"
"os"
"github.com/mattermost/platform/model"
@@ -66,3 +67,11 @@ func GetIpAddress(r *http.Request) string {
return address
}
+
+func GetSiteName(siteURL string) string {
+ u, err := url.Parse(siteURL)
+ if err != nil {
+ return ""
+ }
+ return u.Host
+}