Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

✨ Redirect SES bounce and complaint reports with SES_FEEDBACK_EMAIL (#3431)

Luke Vellad1a886d55c0d
diff --git a/apps/web/src/env.ts b/apps/web/src/env.ts
index 1fcfc4f51..17641f9f0 100644
--- a/apps/web/src/env.ts
+++ b/apps/web/src/env.ts
@@ -59,6 +59,11 @@ export const env = createEnv({
AWS_ACCESS_KEY_ID: z.string().optional(),
AWS_SECRET_ACCESS_KEY: z.string().optional(),
AWS_REGION: z.string().optional(),
+ /**
+ * Where SES sends bounce and complaint reports instead of the From
+ * address. Must be an address on a verified SES identity.
+ */
+ SES_FEEDBACK_EMAIL: z.email().optional(),
/**
* Comma separated list of email addresses that are allowed to register and login.
* If not set, all emails are allowed. Wildcard characters are supported.
@@ -272,6 +277,7 @@ export const env = createEnv({
AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY,
AWS_REGION: process.env.AWS_REGION,
+ SES_FEEDBACK_EMAIL: process.env.SES_FEEDBACK_EMAIL,
S3_BUCKET_NAME: process.env.S3_BUCKET_NAME,
S3_ENDPOINT: process.env.S3_ENDPOINT,
S3_ACCESS_KEY_ID: process.env.S3_ACCESS_KEY_ID,
diff --git a/packages/emails/src/send.test.tsx b/packages/emails/src/send.test.tsx
index 9967b9986..c771e9f2f 100644
--- a/packages/emails/src/send.test.tsx
+++ b/packages/emails/src/send.test.tsx
@@ -73,3 +73,32 @@ test("omits unsubscribe headers when no URL is given", async () => {
expect(sendMail).toHaveBeenCalledTimes(1);
expect(sendMail.mock.calls[0][0]).toMatchObject({ headers: undefined });
});
+
+test("redirects SES feedback to SES_FEEDBACK_EMAIL when set", async () => {
+ process.env.SES_FEEDBACK_EMAIL = "[email protected]";
+ try {
+ await sendRawEmail({
+ subject: "Hello",
+ text: "Hi",
+ });
+ } finally {
+ delete process.env.SES_FEEDBACK_EMAIL;
+ }
+
+ expect(sendMail).toHaveBeenCalledTimes(1);
+ expect(sendMail.mock.calls[0][0]).toMatchObject({
+ ses: { FeedbackForwardingEmailAddress: "[email protected]" },
+ });
+});
+
+test("passes no SES options when SES_FEEDBACK_EMAIL is unset", async () => {
+ await sendRawEmail({
+ subject: "Hello",
+ text: "Hi",
+ });
+
+ expect(sendMail).toHaveBeenCalledTimes(1);
+ expect(sendMail.mock.calls[0][0]).toMatchObject({ ses: undefined });
+});
diff --git a/packages/emails/src/send.tsx b/packages/emails/src/send.tsx
index 19fc97e6e..e8ceec1cb 100644
--- a/packages/emails/src/send.tsx
+++ b/packages/emails/src/send.tsx
@@ -140,6 +140,21 @@ function buildHeaders(
};
}
+/**
+ * SES forwards bounce and complaint reports to the From address unless told
+ * otherwise. A From on the custom MAIL FROM subdomain cannot receive mail (its
+ * MX belongs to SES), so the reports are redirected to a mailbox that can. The
+ * address must belong to a verified SES identity. Ignored by the SMTP
+ * transport.
+ */
+function buildSesOptions(): Record<string, unknown> | undefined {
+ const feedbackAddress = process.env.SES_FEEDBACK_EMAIL;
+ if (!feedbackAddress) {
+ return undefined;
+ }
+ return { FeedbackForwardingEmailAddress: feedbackAddress };
+}
+
async function dispatch(options: DispatchOptions) {
if (!process.env.SUPPORT_EMAIL) {
logger.info("SUPPORT_EMAIL not configured - skipping email send");
@@ -157,6 +172,7 @@ async function dispatch(options: DispatchOptions) {
attachments: options.attachments,
icalEvent: options.icalEvent,
headers: buildHeaders(options.listUnsubscribeUrl),
+ ses: buildSesOptions(),
});
// Proves the hand-off to the server, so "sent but never arrived" can be
// separated from "never sent" without an SMTP transcript.