committed by
GitHub
parent
59dfc0ad91
commit
c185bcfa11
57
apps/dev-tool/app/emails/lib/email-loader.tsx
Normal file
57
apps/dev-tool/app/emails/lib/email-loader.tsx
Normal file
@@ -0,0 +1,57 @@
|
||||
import {
|
||||
renderAccountDeleteEmail,
|
||||
renderInviteEmail,
|
||||
} from '@kit/email-templates';
|
||||
|
||||
export async function loadEmailTemplate(id: string) {
|
||||
if (id === 'account-delete-email') {
|
||||
return renderAccountDeleteEmail({
|
||||
productName: 'Makerkit',
|
||||
userDisplayName: 'Giancarlo',
|
||||
});
|
||||
}
|
||||
|
||||
if (id === 'invite-email') {
|
||||
return renderInviteEmail({
|
||||
teamName: 'Makerkit',
|
||||
teamLogo:
|
||||
'',
|
||||
inviter: 'Giancarlo',
|
||||
invitedUserEmail: 'test@makerkit.dev',
|
||||
link: 'https://makerkit.dev',
|
||||
productName: 'Makerkit',
|
||||
});
|
||||
}
|
||||
|
||||
if (id === 'magic-link-email') {
|
||||
return loadFromFileSystem('magic-link');
|
||||
}
|
||||
|
||||
if (id === 'reset-password-email') {
|
||||
return loadFromFileSystem('reset-password');
|
||||
}
|
||||
|
||||
if (id === 'change-email-address-email') {
|
||||
return loadFromFileSystem('change-email-address');
|
||||
}
|
||||
|
||||
if (id === 'confirm-email') {
|
||||
return loadFromFileSystem('confirm-email');
|
||||
}
|
||||
|
||||
throw new Error(`Email template not found: ${id}`);
|
||||
}
|
||||
|
||||
async function loadFromFileSystem(fileName: string) {
|
||||
const { readFileSync } = await import('node:fs');
|
||||
const { join } = await import('node:path');
|
||||
|
||||
const filePath = join(
|
||||
process.cwd(),
|
||||
`../web/supabase/templates/${fileName}.html`,
|
||||
);
|
||||
|
||||
return {
|
||||
html: readFileSync(filePath, 'utf8'),
|
||||
};
|
||||
}
|
||||
11
apps/dev-tool/app/emails/lib/email-tester-form-schema.ts
Normal file
11
apps/dev-tool/app/emails/lib/email-tester-form-schema.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const EmailTesterFormSchema = z.object({
|
||||
username: z.string().min(1),
|
||||
password: z.string().min(1),
|
||||
sender: z.string().min(1),
|
||||
to: z.string().email(),
|
||||
host: z.string().min(1),
|
||||
port: z.number().min(1),
|
||||
tls: z.boolean(),
|
||||
});
|
||||
38
apps/dev-tool/app/emails/lib/server-actions.ts
Normal file
38
apps/dev-tool/app/emails/lib/server-actions.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
'use server';
|
||||
|
||||
import { loadEmailTemplate } from '@/app/emails/lib/email-loader';
|
||||
|
||||
export async function sendEmailAction(params: {
|
||||
template: string;
|
||||
settings: {
|
||||
username: string;
|
||||
password: string;
|
||||
sender: string;
|
||||
host: string;
|
||||
to: string;
|
||||
port: number;
|
||||
tls: boolean;
|
||||
};
|
||||
}) {
|
||||
const { settings } = params;
|
||||
const { createTransport } = await import('nodemailer');
|
||||
|
||||
const transporter = createTransport({
|
||||
host: settings.host,
|
||||
port: settings.port,
|
||||
secure: settings.tls,
|
||||
auth: {
|
||||
user: settings.username,
|
||||
pass: settings.password,
|
||||
},
|
||||
});
|
||||
|
||||
const { html } = await loadEmailTemplate(params.template);
|
||||
|
||||
return transporter.sendMail({
|
||||
html,
|
||||
from: settings.sender,
|
||||
to: settings.to,
|
||||
subject: 'Test Email',
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user