mirror of
https://github.com/fleetdm/fleet
synced 2026-05-16 21:48:48 +00:00
Related to #15758 Changes: - Updated the copyright year in email templates to be set to the current year when the email is sent. Testing steps: 1. Configure a local Fleet instance to send emails to Mailpit 2. Activate SMTP to send a test email. 3. Invite a new user to the Fleet instance. 4. Change the email address of a user. 5. Log out of the Fleet instance and send a password reset email. 6. Go to the Mailpit dashboard and look at the copyright years in the emails sent by the Fleet instance
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package mail
|
|
|
|
import (
|
|
"bytes"
|
|
"html/template"
|
|
"time"
|
|
|
|
"github.com/fleetdm/fleet/v4/server"
|
|
)
|
|
|
|
type ChangeEmailMailer struct {
|
|
BaseURL template.URL
|
|
AssetURL template.URL
|
|
Token string
|
|
CurrentYear int
|
|
}
|
|
|
|
func (cem *ChangeEmailMailer) Message() ([]byte, error) {
|
|
cem.CurrentYear = time.Now().Year()
|
|
t, err := server.GetTemplate("server/mail/templates/change_email_confirmation.html", "email_template")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var msg bytes.Buffer
|
|
err = t.Execute(&msg, cem)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return msg.Bytes(), nil
|
|
}
|
|
|
|
type PasswordResetMailer struct {
|
|
// Base URL to use for Fleet endpoints
|
|
BaseURL template.URL
|
|
// URL for loading image assets
|
|
AssetURL template.URL
|
|
// Token password reset token
|
|
Token string
|
|
// Current year for copyright year
|
|
CurrentYear int
|
|
}
|
|
|
|
func (r PasswordResetMailer) Message() ([]byte, error) {
|
|
r.CurrentYear = time.Now().Year()
|
|
t, err := server.GetTemplate("server/mail/templates/password_reset.html", "email_template")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var msg bytes.Buffer
|
|
if err = t.Execute(&msg, r); err != nil {
|
|
return nil, err
|
|
}
|
|
return msg.Bytes(), nil
|
|
}
|