Fix various breakages in email links

This commit is contained in:
Eli Ribble 2026-02-02 22:57:19 +00:00
parent 73ed495b72
commit a67279db88
No known key found for this signature in database
8 changed files with 59 additions and 20 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -64,34 +64,34 @@
</head>
<body>
<div class="container">
{{if .IsBrowser}}
{{if not .IsBrowser}}
<div class="view-browser">
Email not displaying correctly? <a href="{{.url_browser}}">View it in your browser</a>
Email not displaying correctly? <a href="{{.C.URLBrowser}}">View it in your browser</a>
</div>
{{end}}
<div class="header">
<!-- Logo Placeholder -->
<img src="{{.URLLogo}}" alt="Report Mosquitoes Online Logo" class="logo"></img>
<img src="{{.C.URLLogo}}" alt="Report Mosquitoes Online Logo" class="logo"></img>
</div>
<div class="content">
<h1>Welcome</h1>
<p>We're sending you this email because it's the first time we've gotten this email address ({{.Destination}}).</p>
<p>We're sending you this email because it's the first time we've gotten this email address ({{.C.Destination}}).</p>
<p>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.</p>
<p>If instead you'd like to confirm that you're willing to receive emails at this address, you can do so by clicking below:</p>
<div style="text-align: center;">
<a href="{{.URLSubscribe}}" class="button">I want emails from Report Mosquitoes Online</a>
<a href="{{.C.URLSubscribe}}" class="button">I want emails from Report Mosquitoes Online</a>
</div>
</div>
<div class="footer">
<p>This email was sent to you because you or someone else gave your email address to Report Mosquitoes Online.</p>
<p>If you no longer wish to receive these updates, <a href="{{.URLUnsubscribe}}">click here to unsubscribe</a>.</p>
<p>If you no longer wish to receive these updates, <a href="{{.C.URLUnsubscribe}}">click here to unsubscribe</a>.</p>
<p>&copy; 2026 Gleipnir LLC. All rights reserved.</p>
</div>
</div>

View file

@ -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

View file

@ -64,35 +64,37 @@
</head>
<body>
<div class="container">
{{if not .IsBrowser}}
<div class="view-browser">
Email not displaying correctly? <a href="{{.URLViewInBrowser}}">View it in your browser</a>
Email not displaying correctly? <a href="{{.C.URLViewInBrowser}}">View it in your browser</a>
</div>
{{end}}
<div class="header">
<!-- Logo Placeholder -->
<img src="{{.URLLogo}}" alt="Report Mosquitoes Online Logo" class="logo">
<img src="{{.C.URLLogo}}" alt="Report Mosquitoes Online Logo" class="logo">
</div>
<div class="content">
<h1>Thank You for Your Report</h1>
<p>We've received your mosquito report {{.ReportIDStr}}. Thanks! We appreciate you taking the time to submit it.</p>
<p>We've received your mosquito report {{.C.ReportIDStr}}. Thanks! We appreciate you taking the time to submit it.</p>
<p>You can check the current status of your report at any time by clicking the button below:</p>
<div style="text-align: center;">
<a href="{{.URLReportStatus}}" class="button">View Report Status</a>
<a href="{{.C.URLReportStatus}}" class="button">View Report Status</a>
</div>
<p>We'll send you additional updates as work is scheduled and completed.</p>
<p>If you have any questions or need further assistance, please don't hesitate to contact us by replying to this email.</p>
<p>You can unsubscribe from notifications about this report by clicking <a hrep="{{.URLReportUnsubscribe}}">here</a></p>
<p>You can unsubscribe from notifications about this report by clicking <a hrep="{{.C.URLReportUnsubscribe}}">here</a></p>
</div>
<div class="footer">
<p>This email was sent to you because you requested updates on your mosquito nuisance report.</p>
<p>If you no longer wish to receive these updates, <a href="{{.URLReportUnsubscribe}}">click here to unsubscribe</a>.</p>
<p>If you no longer wish to receive these updates, <a href="{{.C.URLReportUnsubscribe}}">click here to unsubscribe</a>.</p>
<p>&copy; 2026 Gleipnir LLC. All rights reserved.</p>
</div>
</div>

View file

@ -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.

View file

@ -0,0 +1,24 @@
{{template "base.html" .}}
{{define "title"}}Main{{end}}
{{define "extraheader"}}
{{end}}
{{define "content"}}
<!-- Main Content -->
<main>
<section class="py-2 bg-primary text-white">
<div class="banner-container d-flex justify-content-center">
<img class="banner" src="/static/img/rmo/banner.jpg"/>
</div>
</section>
<section class="py-3 row text-center">
<div class="container">
<h1>Thanks!</h1>
<p>You've allowed emails from Report Mosquitoes Online to {{.Email}}.</p>
<p>Go ahead and close this page/tab/window whenever you're ready...</p>
<p>...or maybe <a href="/">check out the site</a></p>
</div>
</section>
</main>
{{end}}