Skip to content

Commit 6c5fe90

Browse files
committed
added SMTP support and removed resend dependency
1 parent a5b5912 commit 6c5fe90

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

apps/webapp/app/env.server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ const EnvironmentSchema = z.object({
2828
FROM_EMAIL: z.string().optional(),
2929
REPLY_TO_EMAIL: z.string().optional(),
3030
RESEND_API_KEY: z.string().optional(),
31+
SMTP_HOST: z.string(),
32+
SMTP_PORT: z.number(),
33+
SMTP_USER: z.string(),
34+
SMTP_PASSWORD: z.string(),
3135
PLAIN_API_KEY: z.string().optional(),
3236
RUNTIME_PLATFORM: z.enum(["docker-compose", "ecs", "local"]).default("local"),
3337
});

apps/webapp/app/services/email.server.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ import type { AuthUser } from "./authUser";
88
import { workerQueue } from "./worker.server";
99

1010
const client = new EmailClient({
11-
apikey: env.RESEND_API_KEY,
11+
smtpConfig: {
12+
host:env.SMTP_HOST,
13+
secure: true,
14+
port: env.SMTP_PORT,
15+
auth: {
16+
user: env.SMTP_USER,
17+
pass: env.SMTP_PASSWORD,
18+
},
19+
},
1220
imagesBaseUrl: env.APP_ORIGIN,
1321
from: env.FROM_EMAIL ?? "[email protected]",
1422
replyTo: env.REPLY_TO_EMAIL ?? "[email protected]",

packages/emails/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@
2121
"@react-email/render": "^0.0.7",
2222
"@react-email/section": "^0.0.1",
2323
"@react-email/text": "^0.0.2",
24+
"nodemailer": "^6.9.4",
2425
"react": "^18.2.0",
2526
"react-email": "^1.6.1",
26-
"resend": "^0.9.1",
2727
"tiny-invariant": "^1.2.0",
2828
"zod": "3.21.4"
2929
},
3030
"devDependencies": {
31-
"@types/react": "18.2.17",
3231
"@trigger.dev/tsconfig": "workspace:*",
3332
"@types/node": "16",
33+
"@types/nodemailer": "^6.4.9",
34+
"@types/react": "18.2.17",
3435
"typescript": "^4.9.4"
3536
},
3637
"engines": {

packages/emails/src/index.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import WorkflowIntegration from "../emails/workflow-integration";
88
import InviteEmail, { InviteEmailSchema } from "../emails/invite";
99
import { render } from "@react-email/render";
1010

11-
import { Resend } from "resend";
11+
import nodemailer from "nodemailer";
1212
import { z } from "zod";
1313
import React from "react";
1414

@@ -42,15 +42,29 @@ export const DeliverEmailSchema = z
4242

4343
export type DeliverEmail = z.infer<typeof DeliverEmailSchema>;
4444

45+
export type NodeMailerTransportOptions = {
46+
host: string;
47+
port: number;
48+
secure: boolean;
49+
auth: {
50+
user: string;
51+
pass: string;
52+
};
53+
};
54+
4555
export class EmailClient {
46-
#client?: Resend;
56+
#client?: nodemailer.Transporter;
4757
#imagesBaseUrl: string;
4858
#from: string;
4959
#replyTo: string;
5060

51-
constructor(config: { apikey?: string; imagesBaseUrl: string; from: string; replyTo: string }) {
52-
this.#client =
53-
config.apikey && config.apikey.startsWith("re_") ? new Resend(config.apikey) : undefined;
61+
constructor(config: {
62+
smtpConfig: NodeMailerTransportOptions;
63+
imagesBaseUrl: string;
64+
from: string;
65+
replyTo: string;
66+
}) {
67+
this.#client = nodemailer.createTransport(config.smtpConfig);
5468
this.#imagesBaseUrl = config.imagesBaseUrl;
5569
this.#from = config.from;
5670
this.#replyTo = config.replyTo;
@@ -110,12 +124,12 @@ export class EmailClient {
110124

111125
async #sendEmail({ to, subject, react }: { to: string; subject: string; react: ReactElement }) {
112126
if (this.#client) {
113-
await this.#client.sendEmail({
127+
await this.#client.sendMail({
114128
from: this.#from,
115129
to,
116130
replyTo: this.#replyTo,
117131
subject,
118-
react,
132+
html: render(react),
119133
});
120134

121135
return;

0 commit comments

Comments
 (0)