Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: utilize custom SMTP domain if set #25248

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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{"[email protected]"},
SMTPSettings: fleet.SMTPSettings{
SMTPConfigured: true,
SMTPAuthenticationType: fleet.AuthTypeNameNone,
SMTPEnableTLS: false,
SMTPVerifySSLCerts: false,
SMTPEnableStartTLS: false,
SMTPPort: 1027,
SMTPServer: "localhost",
SMTPDomain: "foo.com",
SMTPSenderAddress: "[email protected]",
},
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
Loading