-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add cold email notifier #1117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cold email notifier #1117
Changes from all commits
13d8561
e56172c
b505600
d42a13d
06789e4
4e976a9
854178c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- AlterEnum | ||
| ALTER TYPE "ActionType" ADD VALUE 'NOTIFY_SENDER'; |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,55 @@ | ||||||
| import { sendColdEmailNotification as sendColdEmailNotificationViaResend } from "@inboxzero/resend"; | ||||||
| import { env } from "@/env"; | ||||||
| import { getErrorMessage } from "@/utils/error"; | ||||||
| import type { Logger } from "@/utils/logger"; | ||||||
| import { formatReplySubject } from "@/utils/email/subject"; | ||||||
|
|
||||||
| export async function sendColdEmailNotification({ | ||||||
| senderEmail, | ||||||
| recipientEmail, | ||||||
| originalSubject, | ||||||
| originalMessageId, | ||||||
| logger, | ||||||
| }: { | ||||||
| senderEmail: string; // The cold emailer we're notifying | ||||||
| recipientEmail: string; // The user who received the cold email | ||||||
| originalSubject: string; | ||||||
|
elie222 marked this conversation as resolved.
|
||||||
| originalMessageId?: string; // Message-ID of the original email for threading | ||||||
| logger: Logger; | ||||||
| }): Promise<{ success: boolean; error?: string }> { | ||||||
| if (!env.RESEND_API_KEY) { | ||||||
| logger.warn("Resend not configured, skipping cold email notification"); | ||||||
| return { success: false, error: "Resend not configured" }; | ||||||
| } | ||||||
|
|
||||||
| const subject = formatReplySubject(originalSubject); | ||||||
|
|
||||||
| try { | ||||||
| const result = await sendColdEmailNotificationViaResend({ | ||||||
| from: env.RESEND_FROM_EMAIL, | ||||||
| to: senderEmail, | ||||||
| replyTo: recipientEmail, | ||||||
| subject, | ||||||
| inReplyTo: originalMessageId, | ||||||
| emailProps: { | ||||||
| baseUrl: env.NEXT_PUBLIC_BASE_URL, | ||||||
| }, | ||||||
| }); | ||||||
|
|
||||||
| logger.info("Cold email notification sent", { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
+ if (result.error) {
+ logger.error("Resend returned an error when sending cold email notification", { senderEmail, error: result.error });
+ return { success: false, error: getErrorMessage(result.error) };
+ }
|
||||||
| senderEmail, | ||||||
| messageId: result.data?.id, | ||||||
| }); | ||||||
|
|
||||||
| return { success: true }; | ||||||
| } catch (error) { | ||||||
| logger.error("Error sending cold email notification", { | ||||||
| error, | ||||||
| senderEmail, | ||||||
| }); | ||||||
| return { | ||||||
| success: false, | ||||||
| error: error instanceof Error ? error.message : "Unknown error", | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| }; | ||||||
| } | ||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.