From a67279db8874f416dd621cd8b8ae65bea43d5978 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Mon, 2 Feb 2026 22:57:19 +0000 Subject: [PATCH] Fix various breakages in email links --- comms/email/initial.go | 2 +- .../email/report_notification_confirmation.go | 2 +- comms/email/template.go | 17 +++++++++++-- comms/email/template/initial-contact.html | 12 +++++----- comms/email/template/initial-contact.txt | 4 ++-- .../report-notification-confirmation.html | 14 ++++++----- .../report-notification-confirmation.txt | 4 ++-- rmo/template/email-subscribe-confirm.html | 24 +++++++++++++++++++ 8 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 rmo/template/email-subscribe-confirm.html diff --git a/comms/email/initial.go b/comms/email/initial.go index 940df96e..45438088 100644 --- a/comms/email/initial.go +++ b/comms/email/initial.go @@ -51,7 +51,7 @@ func sendEmailInitialContact(ctx context.Context, destination string) error { data["Source"] = source data["URLBrowser"] = urlEmailInBrowser(public_id) data["URLLogo"] = config.MakeURLReport("/static/img/nidus-logo-no-lettering-64.png") - data["URLSubscribe"] = config.MakeURLReport("/email/subscribe?email=%s", destination) + data["URLSubscribe"] = config.MakeURLReport("/email/confirm?email=%s", destination) data["URLUnsubscribe"] = urlUnsubscribe(destination) text, html, err := renderEmailTemplates(templateInitialID, data) diff --git a/comms/email/report_notification_confirmation.go b/comms/email/report_notification_confirmation.go index 5c9871e0..cf4b7e6f 100644 --- a/comms/email/report_notification_confirmation.go +++ b/comms/email/report_notification_confirmation.go @@ -53,7 +53,7 @@ func sendEmailReportConfirmation(ctx context.Context, job Job) error { report_id_str := publicReportID(j.reportID) data["ReportIDStr"] = report_id_str data["URLLogo"] = config.MakeURLReport("/static/img/nidus-logo-no-lettering-64.png") - data["URLReportStatus"] = config.MakeURLReport("/foo") + data["URLReportStatus"] = config.MakeURLReport("/status/%s", j.reportID) data["URLReportUnsubscribe"] = config.MakeURLReport("/email/unsubscribe/report/%s", j.reportID) data["URLUnsubscribe"] = urlUnsubscribe(j.destination()) data["URLViewInBrowser"] = urlEmailInBrowser(public_id) diff --git a/comms/email/template.go b/comms/email/template.go index c3ad1a2c..cc7dcd29 100644 --- a/comms/email/template.go +++ b/comms/email/template.go @@ -37,6 +37,11 @@ var ( templateReportNotificationConfirmationID int32 ) +type ContentEmailRender struct { + IsBrowser bool + C any +} + type templatePair struct { baseName string messageType enums.CommsMessagetypeemail @@ -98,7 +103,11 @@ func RenderHTML(template_id int32, s pgtypes.HStore) (html []byte, err error) { return []byte{}, fmt.Errorf("Failed to lookup template %d", template_id) } buf_html := &bytes.Buffer{} - err = t.executeTemplateHTML(buf_html, data) + content := ContentEmailRender{ + C: data, + IsBrowser: true, + } + err = t.executeTemplateHTML(buf_html, content) if err != nil { return []byte{}, fmt.Errorf("Failed to render HTML template: %w", err) } @@ -320,12 +329,16 @@ func publicReportID(s string) string { return s[0:4] + "-" + s[4:8] + "-" + s[8:12] } -func renderEmailTemplates(template_id int32, content map[string]string) (text string, html string, err error) { +func renderEmailTemplates(template_id int32, data map[string]string) (text string, html string, err error) { buf_txt := &bytes.Buffer{} t, ok := templateByID[template_id] if !ok { return "", "", fmt.Errorf("Failed to lookup template %d", template_id) } + content := ContentEmailRender{ + C: data, + IsBrowser: false, + } err = t.executeTemplateTXT(buf_txt, content) if err != nil { return "", "", fmt.Errorf("Failed to render TXT template: %w", err) diff --git a/comms/email/template/initial-contact.html b/comms/email/template/initial-contact.html index f30b6960..48f9e7c0 100644 --- a/comms/email/template/initial-contact.html +++ b/comms/email/template/initial-contact.html @@ -64,34 +64,34 @@
- {{if .IsBrowser}} + {{if not .IsBrowser}}
- Email not displaying correctly? View it in your browser + Email not displaying correctly? View it in your browser
{{end}}
- +

Welcome

-

We're sending you this email because it's the first time we've gotten this email address ({{.Destination}}).

+

We're sending you this email because it's the first time we've gotten this email address ({{.C.Destination}}).

If you'd rather not receive emails from us you can reply with "Unsubscribe" in the subject or body of the email. You can also use the "Unsubscribe" feature of your mail client, if it supports list unsubscribes.

If instead you'd like to confirm that you're willing to receive emails at this address, you can do so by clicking below:

- I want emails from Report Mosquitoes Online + I want emails from Report Mosquitoes Online
diff --git a/comms/email/template/initial-contact.txt b/comms/email/template/initial-contact.txt index 92c358cd..8b7ff095 100644 --- a/comms/email/template/initial-contact.txt +++ b/comms/email/template/initial-contact.txt @@ -1,6 +1,6 @@ -We're sending you this email because it's the first time we've gotten this email address ({{.Destination}}). +We're sending you this email because it's the first time we've gotten this email address ({{.C.Destination}}). If you'd rather not receive emails from us you can reply with "Unsubscribe" in the subject or body of the email. You can also use the "Unsubscribe" feature of your mail client, if it supports list unsubscribes. -If instead you'd like to confirm that you're willing to receive emails at this address, you can do so by openining the following URL in a web browser: {{.URLSubscribe}}. You can also confirm your willingness by replying to this email with 'Confirm' in the subject on the body of the email. +If instead you'd like to confirm that you're willing to receive emails at this address, you can do so by openining the following URL in a web browser: {{.C.URLSubscribe}}. You can also confirm your willingness by replying to this email with 'Confirm' in the subject on the body of the email. Thank you, Report Mosquitoes Online diff --git a/comms/email/template/report-notification-confirmation.html b/comms/email/template/report-notification-confirmation.html index 2ae0db35..c0537cda 100644 --- a/comms/email/template/report-notification-confirmation.html +++ b/comms/email/template/report-notification-confirmation.html @@ -64,35 +64,37 @@
+ {{if not .IsBrowser}}
- Email not displaying correctly? View it in your browser + Email not displaying correctly? View it in your browser
+ {{end}}
- +

Thank You for Your Report

-

We've received your mosquito report {{.ReportIDStr}}. Thanks! We appreciate you taking the time to submit it.

+

We've received your mosquito report {{.C.ReportIDStr}}. Thanks! We appreciate you taking the time to submit it.

You can check the current status of your report at any time by clicking the button below:

- View Report Status + View Report Status

We'll send you additional updates as work is scheduled and completed.

If you have any questions or need further assistance, please don't hesitate to contact us by replying to this email.

-

You can unsubscribe from notifications about this report by clicking here

+

You can unsubscribe from notifications about this report by clicking here

diff --git a/comms/email/template/report-notification-confirmation.txt b/comms/email/template/report-notification-confirmation.txt index 31df8a44..dd93f2c6 100644 --- a/comms/email/template/report-notification-confirmation.txt +++ b/comms/email/template/report-notification-confirmation.txt @@ -1,9 +1,9 @@ We've received your mosquito report. Thanks! We appreciate you taking the time to submit it. -You can check the current status of your report at any time at {{.URLReportStatus}} +You can check the current status of your report at any time at {{.C.URLReportStatus}} We'll send you additional updates as work is scheduled and completed. If you have any questions or need further assistance, please don't hesitate to contact us by replying to this email. -If you no longer wish to receive these updates, navigate your browser to {{.URLReportUnsubscribe}} to unsubscribe. +If you no longer wish to receive these updates, navigate your browser to {{.C.URLReportUnsubscribe}} to unsubscribe. diff --git a/rmo/template/email-subscribe-confirm.html b/rmo/template/email-subscribe-confirm.html new file mode 100644 index 00000000..d88a5b08 --- /dev/null +++ b/rmo/template/email-subscribe-confirm.html @@ -0,0 +1,24 @@ +{{template "base.html" .}} + +{{define "title"}}Main{{end}} +{{define "extraheader"}} +{{end}} +{{define "content"}} + +
+
+ +
+
+
+

Thanks!

+

You've allowed emails from Report Mosquitoes Online to {{.Email}}.

+

Go ahead and close this page/tab/window whenever you're ready...

+

...or maybe check out the site

+
+
+
+ +{{end}}