diff --git a/server/mail/mail.go b/server/mail/mail.go index 129646bda545..972c6fee30a7 100644 --- a/server/mail/mail.go +++ b/server/mail/mail.go @@ -198,6 +198,11 @@ func (m mailService) sendMail(e fleet.Email, msg []byte) error { } defer client.Close() + if e.SMTPSettings.SMTPDomain != "" { + if err = client.Hello(e.SMTPSettings.SMTPDomain); err != nil { + return fmt.Errorf("client hello error: %w", err) + } + } if e.SMTPSettings.SMTPEnableStartTLS { if ok, _ := client.Extension("STARTTLS"); ok { if err = client.StartTLS(tlsConfig); err != nil { diff --git a/server/mail/mail_test.go b/server/mail/mail_test.go index 6e41f97c92b3..65fe7502e31c 100644 --- a/server/mail/mail_test.go +++ b/server/mail/mail_test.go @@ -17,6 +17,7 @@ var testFunctions = [...]func(*testing.T, fleet.MailService){ testSMTPPlainAuthInvalidCreds, testSMTPSkipVerify, testSMTPNoAuthWithTLS, + testSMTPDomain, testMailTest, } @@ -159,6 +160,31 @@ func testSMTPNoAuthWithTLS(t *testing.T, mailer fleet.MailService) { assert.Nil(t, err) } +func testSMTPDomain(t *testing.T, mailer fleet.MailService) { + mail := fleet.Email{ + Subject: "custom client hello", + To: []string{"bob@foo.com"}, + SMTPSettings: fleet.SMTPSettings{ + SMTPConfigured: true, + SMTPAuthenticationType: fleet.AuthTypeNameNone, + SMTPEnableTLS: false, + SMTPVerifySSLCerts: false, + SMTPEnableStartTLS: false, + SMTPPort: 1027, + SMTPServer: "localhost", + SMTPDomain: "foo.com", + SMTPSenderAddress: "test@example.com", + }, + Mailer: &SMTPTestMailer{ + BaseURL: "https://localhost:8080", + }, + } + + err := mailer.SendEmail(mail) + assert.Nil(t, err) + +} + func testMailTest(t *testing.T, mailer fleet.MailService) { mail := fleet.Email{ Subject: "test tester",