send-mail refactor (#7885)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
1ccf093803
Коммит
bbb301b7de
@@ -103,10 +103,6 @@ func TestConnection(config *model.Config) {
|
||||
defer c.Close()
|
||||
}
|
||||
|
||||
func SendMail(to, subject, htmlBody string) *model.AppError {
|
||||
return SendMailUsingConfig(to, subject, htmlBody, Cfg)
|
||||
}
|
||||
|
||||
func SendMailUsingConfig(to, subject, htmlBody string, config *model.Config) *model.AppError {
|
||||
if !config.EmailSettings.SendEmailNotifications || len(config.EmailSettings.SMTPServer) == 0 {
|
||||
return nil
|
||||
|
||||
@@ -9,30 +9,30 @@ import (
|
||||
)
|
||||
|
||||
func TestMailConnection(t *testing.T) {
|
||||
LoadGlobalConfig("config.json")
|
||||
cfg := LoadGlobalConfig("config.json")
|
||||
|
||||
if conn, err := connectToSMTPServer(Cfg); err != nil {
|
||||
if conn, err := connectToSMTPServer(cfg); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should connect to the STMP Server")
|
||||
} else {
|
||||
if _, err1 := newSMTPClient(conn, Cfg); err1 != nil {
|
||||
if _, err1 := newSMTPClient(conn, cfg); err1 != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should get new smtp client")
|
||||
}
|
||||
}
|
||||
|
||||
Cfg.EmailSettings.SMTPServer = "wrongServer"
|
||||
Cfg.EmailSettings.SMTPPort = "553"
|
||||
cfg.EmailSettings.SMTPServer = "wrongServer"
|
||||
cfg.EmailSettings.SMTPPort = "553"
|
||||
|
||||
if _, err := connectToSMTPServer(Cfg); err == nil {
|
||||
if _, err := connectToSMTPServer(cfg); err == nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should not to the STMP Server")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestSendMail(t *testing.T) {
|
||||
LoadGlobalConfig("config.json")
|
||||
func TestSendMailUsingConfig(t *testing.T) {
|
||||
cfg := LoadGlobalConfig("config.json")
|
||||
T = GetUserTranslations("en")
|
||||
|
||||
var emailTo string = "test@example.com"
|
||||
@@ -42,7 +42,7 @@ func TestSendMail(t *testing.T) {
|
||||
//Delete all the messages before check the sample email
|
||||
DeleteMailBox(emailTo)
|
||||
|
||||
if err := SendMail(emailTo, emailSubject, emailBody); err != nil {
|
||||
if err := SendMailUsingConfig(emailTo, emailSubject, emailBody, cfg); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should connect to the STMP Server")
|
||||
} else {
|
||||
|
||||
Ссылка в новой задаче
Block a user