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
This commit is contained in:
Eric 2024-01-15 15:28:49 -06:00 committed by GitHub
parent 43f21baa86
commit cd63133770
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 13 deletions

View File

@ -3,6 +3,7 @@ package mail
import (
"bytes"
"html/template"
"time"
"github.com/fleetdm/fleet/v4/server"
"github.com/fleetdm/fleet/v4/server/fleet"
@ -11,13 +12,15 @@ import (
// 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
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

View File

@ -275,11 +275,13 @@ func dialTimeout(addr string, tlsConfig *tls.Config) (client *smtp.Client, err e
// SMTPTestMailer is used to build an email message that will be used as
// a test message when testing SMTP configuration
type SMTPTestMailer struct {
BaseURL template.URL
AssetURL template.URL
BaseURL template.URL
AssetURL template.URL
CurrentYear int
}
func (m *SMTPTestMailer) Message() ([]byte, error) {
m.CurrentYear = time.Now().Year()
t, err := server.GetTemplate("server/mail/templates/smtp_setup.html", "email_template")
if err != nil {
return nil, err

View File

@ -162,7 +162,7 @@
</a>
</div>
<p style="font-size: 12px; line-height: 16px; padding: 0">
© 2022 Fleet Device Management Inc. <br />
© {{.CurrentYear}} Fleet Device Management Inc. <br />
All trademarks, service marks, and company names are the
property of their respective owners.
</p>

View File

@ -192,7 +192,7 @@
</a>
</div>
<p style="font-size: 12px; line-height: 16px; padding: 0">
© 2022 Fleet Device Management Inc. <br />
© {{.CurrentYear}} Fleet Device Management Inc. <br />
All trademarks, service marks, and company names are the
property of their respective owners.
</p>

View File

@ -167,7 +167,7 @@
</a>
</div>
<p style="font-size: 12px; line-height: 16px; padding: 0">
© 2022 Fleet Device Management Inc. <br />
© {{.CurrentYear}} Fleet Device Management Inc. <br />
All trademarks, service marks, and company names are the
property of their respective owners.
</p>

View File

@ -141,7 +141,7 @@
</a>
</div>
<p style="font-size: 12px; line-height: 16px; padding: 0;">
© 2022 Fleet Device Management Inc. <br />
© {{.CurrentYear}} Fleet Device Management Inc. <br />
All trademarks, service marks, and company names are the
property of their respective owners.
</p>

View File

@ -3,17 +3,20 @@ package mail
import (
"bytes"
"html/template"
"time"
"github.com/fleetdm/fleet/v4/server"
)
type ChangeEmailMailer struct {
BaseURL template.URL
AssetURL template.URL
Token string
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
@ -33,9 +36,12 @@ type PasswordResetMailer struct {
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