Skip to content

Commit

Permalink
feat: unsub footer; refactor: no html content
Browse files Browse the repository at this point in the history
  • Loading branch information
mplewis committed Nov 20, 2024
1 parent 149ab3d commit 1d04923
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
7 changes: 5 additions & 2 deletions api/src/lib/email/send.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ describe('mailer', () => {
"handler": "nodemailer",
"handlerOptions": undefined,
"headers": {},
"htmlContent": "Leave this email here",
"htmlContent": null,
"renderer": "plain",
"rendererOptions": {},
"replyTo": undefined,
"subject": "Don't delete me",
"textContent": "Leave this email here",
"textContent": "Leave this email here
To unsubscribe from all Freevite emails forever, click here:
https://example.com/unsubscribe?email=darlene%40fs0ciety.pizza&token=wgPFf2G9H7D9zKIEjop_AeZCED7pLZex619NqYasXwk",
"to": [
"[email protected]",
],
Expand Down
8 changes: 6 additions & 2 deletions api/src/lib/email/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { mailer } from 'src/lib/mailer'
import { logger } from '../logger'

import { Plain } from './plain'
import { unsubscribeFooter } from './unsubscribe'

interface Params {
to: string | string[]
Expand All @@ -16,10 +17,13 @@ interface Params {
* @param params The email parameters
* @returns The result of the send operation
*/
export async function sendEmail({ subject, text, ...p }: Params) {
export async function sendEmail({ subject, text: _text, ...p }: Params) {
const firstRecipient = Array.isArray(p.to) ? p.to[0] : p.to
const to = Array.isArray(p.to) ? p.to : [p.to]

const text = _text.trim() + '\n\n' + unsubscribeFooter(firstRecipient)
const { name, email } = MAIL_SENDER
const from = `"${name}" <${email}>`
const to = Array.isArray(p.to) ? p.to : [p.to]
logger.info({ from, to, subject, text }, 'Sending email')
return mailer.send(Plain({ text }), { subject, from, to })
}
7 changes: 5 additions & 2 deletions api/src/lib/email/template/event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('with test handler', () => {
"handler": "nodemailer",
"handlerOptions": undefined,
"headers": {},
"htmlContent": "Hello from Freevite! Click this link to manage your event details and make it public:<br><br>https://example.com/edit?token=SOME-EDIT-TOKEN<br><br>You must click the above link within 24 hours to confirm your email address.<br>Otherwise, we will automatically delete your event. Feel free to recreate it.<br><br>If you did not create this event, you can ignore this email and this event will be deleted.<br><br>If you need any help, just reply to this email. Thanks for using Freevite!",
"htmlContent": null,
"renderer": "plain",
"rendererOptions": {},
"replyTo": undefined,
Expand All @@ -45,7 +45,10 @@ Otherwise, we will automatically delete your event. Feel free to recreate it.
If you did not create this event, you can ignore this email and this event will be deleted.
If you need any help, just reply to this email. Thanks for using Freevite!",
If you need any help, just reply to this email. Thanks for using Freevite!
To unsubscribe from all Freevite emails forever, click here:
https://example.com/unsubscribe?email=emma%40example.com&token=oyTyug8SP9wjzqGkAI7AKThdFp4hQs0bBLAPfq1SbRs",
"to": [
"[email protected]",
],
Expand Down
7 changes: 5 additions & 2 deletions api/src/lib/email/template/reminder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('with test handler', () => {
"handler": "nodemailer",
"handlerOptions": undefined,
"headers": {},
"htmlContent": "Hello from Freevite! You asked for a reminder about this event when you RSVPed:<br><br>Emma&#39;s Holiday Party<br>Starts at: Sun Dec 25, 2022, 7:00 AM EST (in a day))<br>Ends at: Sun Dec 25, 2022, 10:00 AM EST (3 hours long)<br><br>View the event here:<br>https://example.com/events/emmas-holiday-party<br><br>Thanks for using Freevite!",
"htmlContent": null,
"renderer": "plain",
"rendererOptions": {},
"replyTo": undefined,
Expand All @@ -51,7 +51,10 @@ Ends at: Sun Dec 25, 2022, 10:00 AM EST (3 hours long)
View the event here:
https://example.com/events/emmas-holiday-party
Thanks for using Freevite!",
Thanks for using Freevite!
To unsubscribe from all Freevite emails forever, click here:
https://example.com/unsubscribe?email=holmes%40example.com&token=xZPATAWTt2b9dRKrUFJ9yE982ThnnvUg6APxtN_gr8s",
"to": [
"[email protected]",
],
Expand Down
21 changes: 15 additions & 6 deletions api/src/lib/email/template/response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('with test handler', () => {
"handler": "nodemailer",
"handlerOptions": undefined,
"headers": {},
"htmlContent": "Hello from Freevite!<br><br>Click here to confirm you&#39;re attending Emma&#39;s Holiday Party:<br>https://example.com/rsvp?token=SOME-EDIT-TOKEN<br>Once you do, we&#39;ll confirm your RSVP and notify the event organizer.<br><br>To change your response or delete your RSVP, click the link above.<br><br>If you did not RSVP to this event, you can ignore this email.",
"htmlContent": null,
"renderer": "plain",
"rendererOptions": {},
"replyTo": undefined,
Expand All @@ -50,7 +50,10 @@ Once you do, we'll confirm your RSVP and notify the event organizer.
To change your response or delete your RSVP, click the link above.
If you did not RSVP to this event, you can ignore this email.",
If you did not RSVP to this event, you can ignore this email.
To unsubscribe from all Freevite emails forever, click here:
https://example.com/unsubscribe?email=holmes%40example.com&token=xZPATAWTt2b9dRKrUFJ9yE982ThnnvUg6APxtN_gr8s",
"to": [
"[email protected]",
],
Expand Down Expand Up @@ -83,7 +86,7 @@ If you did not RSVP to this event, you can ignore this email.",
"handler": "nodemailer",
"handlerOptions": undefined,
"headers": {},
"htmlContent": "Hello from Freevite! Sherlock Holmes has confirmed they are attending Emma&#39;s Holiday Party:<br><br>Name: Sherlock Holmes<br>Guests: 2<br>Comment: Looking forward to it!<br><br>To view all responses and manage your event, click here:<br>https://example.com/edit?token=SOME-EDIT-TOKEN<br><br>Thanks for using Freevite!",
"htmlContent": null,
"renderer": "plain",
"rendererOptions": {},
"replyTo": undefined,
Expand All @@ -97,7 +100,10 @@ Comment: Looking forward to it!
To view all responses and manage your event, click here:
https://example.com/edit?token=SOME-EDIT-TOKEN
Thanks for using Freevite!",
Thanks for using Freevite!
To unsubscribe from all Freevite emails forever, click here:
https://example.com/unsubscribe?email=emma%40example.com&token=oyTyug8SP9wjzqGkAI7AKThdFp4hQs0bBLAPfq1SbRs",
"to": [
"[email protected]",
],
Expand Down Expand Up @@ -130,7 +136,7 @@ Thanks for using Freevite!",
"handler": "nodemailer",
"handlerOptions": undefined,
"headers": {},
"htmlContent": "Hello from Freevite! Sherlock Holmes has canceled their RSVP to Emma&#39;s Holiday Party.<br><br>Here are the details of the RSVP before it was canceled:<br>Name: Sherlock Holmes<br>Guests: 2<br>Comment: Looking forward to it!<br><br>To view all RSVPs and manage your event, click here:<br>https://example.com/edit?token=SOME-EDIT-TOKEN<br><br>Thanks for using Freevite!",
"htmlContent": null,
"renderer": "plain",
"rendererOptions": {},
"replyTo": undefined,
Expand All @@ -145,7 +151,10 @@ Comment: Looking forward to it!
To view all RSVPs and manage your event, click here:
https://example.com/edit?token=SOME-EDIT-TOKEN
Thanks for using Freevite!",
Thanks for using Freevite!
To unsubscribe from all Freevite emails forever, click here:
https://example.com/unsubscribe?email=emma%40example.com&token=oyTyug8SP9wjzqGkAI7AKThdFp4hQs0bBLAPfq1SbRs",
"to": [
"[email protected]",
],
Expand Down
3 changes: 1 addition & 2 deletions api/src/lib/mailer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { render as reactEmailRender } from '@react-email/render'
import escapeHTML from 'escape-html'

import { Mailer } from '@redwoodjs/mailer-core'
import { AbstractMailRenderer } from '@redwoodjs/mailer-core'
Expand All @@ -20,7 +19,7 @@ class PlainEmailRenderer extends AbstractMailRenderer {
_utilities?: MailUtilities
): MailRenderedContent {
const text = template.props.children
const html = escapeHTML(text).replace(/\n/g, '<br>')
const html = null
return { text, html }
}

Expand Down

0 comments on commit 1d04923

Please sign in to comment.