diff --git a/comms/email/initial.go b/comms/email/initial.go index dbf92192..eb60a625 100644 --- a/comms/email/initial.go +++ b/comms/email/initial.go @@ -36,17 +36,20 @@ func maybeSendInitialEmail(ctx context.Context, destination string) error { return sendEmailInitialContact(ctx, destination) } +func urlEmailInBrowser(public_id string) string { + return config.MakeURLReport("/email/render/%s", public_id) +} func sendEmailInitialContact(ctx context.Context, destination string) error { //data := pgtypes.HStore{} data := make(map[string]string, 0) - source := config.ForwardEmailReportAddress - data["destination"] = destination - data["source"] = source - data["url_logo"] = config.MakeURLReport("/static/img/nidus-logo-no-lettering-64.png") - data["url_subscribe"] = config.MakeURLReport("/email/subscribe?email=%s", destination) - data["url_unsubscribe"] = config.MakeURLReport("/email/unsubscribe") public_id := generatePublicId(enums.CommsMessagetypeemailInitialContact, data) - data["url_browser"] = config.MakeURLReport("/email/%s", public_id) + source := config.ForwardEmailReportAddress + data["Destination"] = destination + 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["URLUnsubscribe"] = config.MakeURLReport("/email/unsubscribe") text, html, err := renderEmailTemplates(templateInitialID, data) if err != nil { diff --git a/comms/email/report_notification_confirmation.go b/comms/email/report_notification_confirmation.go index 756a37bc..7aa23501 100644 --- a/comms/email/report_notification_confirmation.go +++ b/comms/email/report_notification_confirmation.go @@ -55,7 +55,7 @@ func sendEmailReportConfirmation(ctx context.Context, job Job) error { data["URLLogo"] = config.MakeURLReport("/static/img/nidus-logo-no-lettering-64.png") data["URLReportStatus"] = config.MakeURLReport("/foo") data["URLReportUnsubscribe"] = config.MakeURLReport("/email/unsubscribe") - data["URLViewInBrowser"] = config.MakeURLReport("/email/%s", public_id) + data["URLViewInBrowser"] = urlEmailInBrowser(public_id) text, html, err := renderEmailTemplates(templateReportNotificationConfirmationID, data) if err != nil { return fmt.Errorf("Failed to render email report notification template: %w", err) diff --git a/comms/email/template/initial-contact.html b/comms/email/template/initial-contact.html index 341e3ae4..f30b6960 100644 --- a/comms/email/template/initial-contact.html +++ b/comms/email/template/initial-contact.html @@ -64,32 +64,34 @@
+ {{if .IsBrowser}}
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 ({{.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/rmo/email.go b/rmo/email.go index 4a0e8106..df3db1cd 100644 --- a/rmo/email.go +++ b/rmo/email.go @@ -6,9 +6,18 @@ import ( "github.com/Gleipnir-Technology/nidus-sync/comms/email" "github.com/Gleipnir-Technology/nidus-sync/db" "github.com/Gleipnir-Technology/nidus-sync/db/models" + "github.com/Gleipnir-Technology/nidus-sync/html" "github.com/go-chi/chi/v5" ) +type ContentEmailSubscribe struct { + Email string +} + +var ( + EmailSubscribeT = buildTemplate("email-subscribe", "base") +) + func getEmailByCode(w http.ResponseWriter, r *http.Request) { id := chi.URLParam(r, "code") //id := r.FormValue("id") @@ -31,3 +40,13 @@ func getEmailByCode(w http.ResponseWriter, r *http.Request) { } w.Write(html) } +func getEmailSubscribe(w http.ResponseWriter, r *http.Request) { + email := r.FormValue("email") + html.RenderOrError( + w, + EmailSubscribeT, + ContentEmailSubscribe{ + Email: email, + }, + ) +} diff --git a/rmo/routes.go b/rmo/routes.go index f3028dad..ad664929 100644 --- a/rmo/routes.go +++ b/rmo/routes.go @@ -24,7 +24,8 @@ func Router() chi.Router { r.Get("/privacy", getPrivacy) r.Get("/robots.txt", getRobots) - r.Get("/email/{code}", getEmailByCode) + r.Get("/email/render/{code}", getEmailByCode) + r.Get("/email/subscribe", getEmailSubscribe) r.Get("/image/{uuid}", getImageByUUID) r.Route("/mock", addMockRoutes) r.Get("/pool-submit-complete", getPoolSubmitComplete) diff --git a/rmo/template/email-subscribe.html b/rmo/template/email-subscribe.html new file mode 100644 index 00000000..fa7469a7 --- /dev/null +++ b/rmo/template/email-subscribe.html @@ -0,0 +1,22 @@ +{{template "base.html" .}} + +{{define "title"}}Main{{end}} +{{define "extraheader"}} +{{end}} +{{define "content"}} + +
+
+ +
+
+
+

Thanks!

+

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

+
+
+
+ +{{end}}