From 0df61d161f98183069494cc349d18f01d8783453 Mon Sep 17 00:00:00 2001 From: Carlos Tadeu Panato Junior Date: Tue, 9 May 2017 15:34:30 +0200 Subject: implement PLT-6469 - Send HELO request containing domain name to SMTP server (#6322) --- i18n/en.json | 8 ++++++++ utils/mail.go | 10 ++++++++++ utils/utils.go | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/i18n/en.json b/i18n/en.json index 4c8a80507..3aaabc686 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -5902,6 +5902,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", @@ -5911,6 +5915,10 @@ "id": "utils.mail.new_client.open.error", "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 +} -- cgit v1.2.3-1-g7c22