fleet/server/mail/invite.go
Eric cd63133770
Dynamically set copyright year in email templates (#16092)
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
2024-01-15 15:28:49 -06:00

35 lines
699 B
Go

package mail
import (
"bytes"
"html/template"
"time"
"github.com/fleetdm/fleet/v4/server"
"github.com/fleetdm/fleet/v4/server/fleet"
)
// InviteMailer is used to build an email template for the invite email.
type InviteMailer struct {
*fleet.Invite
BaseURL template.URL
AssetURL template.URL
InvitedBy string
OrgName string
CurrentYear int
}
func (i *InviteMailer) Message() ([]byte, error) {
i.CurrentYear = time.Now().Year()
t, err := server.GetTemplate("server/mail/templates/invite_token.html", "email_template")
if err != nil {
return nil, err
}
var msg bytes.Buffer
if err = t.Execute(&msg, i); err != nil {
return nil, err
}
return msg.Bytes(), nil
}