Skip to content

Commit

Permalink
fix: utilize custom SMTP domain if set
Browse files Browse the repository at this point in the history
  • Loading branch information
mccormickt committed Jan 8, 2025
1 parent e956220 commit 81a3c6d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/mail/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 26 additions & 0 deletions server/mail/mail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var testFunctions = [...]func(*testing.T, fleet.MailService){
testSMTPPlainAuthInvalidCreds,
testSMTPSkipVerify,
testSMTPNoAuthWithTLS,
testSMTPDomain,
testMailTest,
}

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 81a3c6d

Please sign in to comment.