-
-
Notifications
You must be signed in to change notification settings - Fork 860
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,15 @@ import type { AuthUser } from "./authUser"; | |
import { workerQueue } from "./worker.server"; | ||
|
||
const client = new EmailClient({ | ||
apikey: env.RESEND_API_KEY, | ||
smtpConfig: { | ||
host: env.SMTP_HOST, | ||
secure: true, | ||
port: env.SMTP_PORT, | ||
auth: { | ||
user: env.SMTP_USER, | ||
pass: env.SMTP_PASSWORD, | ||
}, | ||
}, | ||
imagesBaseUrl: env.APP_ORIGIN, | ||
from: env.FROM_EMAIL ?? "[email protected]", | ||
replyTo: env.REPLY_TO_EMAIL ?? "[email protected]", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,9 +82,9 @@ Both of these secrets should be set to the base URL of your fly application. For | |
|
||
 | ||
|
||
`RESEND_API_KEY`, `FROM_EMAIL` and `REPLY_TO_EMAIL` | ||
`FROM_EMAIL`,`REPLY_TO_EMAIL`, `SMTP_HOST`, `SMTP_PORT`, `SMTP_USER` and `SMTP_PASSWORD` | ||
|
||
We use [Resend.com](https://resend.com) for email sending (including the magic-link signup/login system). They have a generous free tier of 100 emails a day that should be sufficient. Signup for Resend.com and enter the environment vars below | ||
We use SMTP for email sending (including the magic-link signup/login system). | ||
|
||
## Set the secrets | ||
|
||
|
@@ -99,7 +99,10 @@ fly secrets set \ | |
APP_ORIGIN="https://<fly app name>.fly.dev" \ | ||
FROM_EMAIL="Acme Inc. <[email protected]>" \ | ||
REPLY_TO_EMAIL="Acme Inc. <[email protected]>" \ | ||
RESEND_API_KEY=<your API Key> \ | ||
SMTP_HOST= < your SMTP host > \ | ||
SMTP_PORT= < your SMTP port > \ | ||
SMTP_USER= < your SMTP user > \ | ||
SMTP_PASSWORD= < your SMTP password > \ | ||
AUTH_GITHUB_CLIENT_ID=<your GitHub OAuth Client ID> \ | ||
AUTH_GITHUB_CLIENT_SECRET=<your GitHUb OAuth Client Secret> | ||
|
||
|
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; | ||
|
||
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.