-
-
Notifications
You must be signed in to change notification settings - Fork 773
added SMTP support and removed resend dependency #313
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
Changes from 3 commits
6c5fe90
ea9b678
242928f
63f0c45
55c5df6
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ import WorkflowIntegration from "../emails/workflow-integration"; | |
import InviteEmail, { InviteEmailSchema } from "../emails/invite"; | ||
import { render } from "@react-email/render"; | ||
|
||
import { Resend } from "resend"; | ||
import nodemailer from "nodemailer"; | ||
import { z } from "zod"; | ||
import React from "react"; | ||
|
||
|
@@ -42,15 +42,29 @@ export const DeliverEmailSchema = z | |
|
||
export type DeliverEmail = z.infer<typeof DeliverEmailSchema>; | ||
|
||
export type NodeMailerTransportOptions = { | ||
host?: string; | ||
port?: number; | ||
secure?: boolean; | ||
auth?: { | ||
user?: string; | ||
pass?: string; | ||
}; | ||
}; | ||
|
||
export class EmailClient { | ||
#client?: Resend; | ||
#client?: nodemailer.Transporter; | ||
#imagesBaseUrl: string; | ||
#from: string; | ||
#replyTo: string; | ||
|
||
constructor(config: { apikey?: string; imagesBaseUrl: string; from: string; replyTo: string }) { | ||
this.#client = | ||
config.apikey && config.apikey.startsWith("re_") ? new Resend(config.apikey) : undefined; | ||
constructor(config: { | ||
smtpConfig?: NodeMailerTransportOptions; | ||
imagesBaseUrl: string; | ||
from: string; | ||
replyTo: string; | ||
}) { | ||
this.#client = config.smtpConfig ? nodemailer.createTransport(config.smtpConfig) : undefined; | ||
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. 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. I'm sorry but I don't quite understand this 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. @ericallam Should I put back the resend api key and dependency as a fallback to when the smtp config doesn't exist? 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. I think Eric just meant the config values should be checked instead of the entire object. Otherwise, this will never return 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. Ohh, makes sense. Thanks |
||
this.#imagesBaseUrl = config.imagesBaseUrl; | ||
this.#from = config.from; | ||
this.#replyTo = config.replyTo; | ||
|
@@ -110,12 +124,12 @@ export class EmailClient { | |
|
||
async #sendEmail({ to, subject, react }: { to: string; subject: string; react: ReactElement }) { | ||
if (this.#client) { | ||
await this.#client.sendEmail({ | ||
await this.#client.sendMail({ | ||
from: this.#from, | ||
to, | ||
replyTo: this.#replyTo, | ||
subject, | ||
react, | ||
html: render(react), | ||
}); | ||
|
||
return; | ||
|
Uh oh!
There was an error while loading. Please reload this page.