implement PLT-6469 - Send HELO request containing domain name to SMTP server (#6322)

Этот коммит содержится в:
Carlos Tadeu Panato Junior
2017-05-09 15:34:30 +02:00
коммит произвёл Harrison Healey
родитель 622998add1
Коммит 0df61d161f
3 изменённых файлов: 27 добавлений и 0 удалений

Просмотреть файл

@@ -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"

Просмотреть файл

@@ -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())
}

Просмотреть файл

@@ -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
}