feat: added mail sender as env
This commit is contained in:
committed by
Carl-Gerhard Lindesvärd
parent
0ce963fc7e
commit
1dfa079b1e
@@ -1,16 +1,16 @@
|
|||||||
import React from 'react';
|
import React from "react";
|
||||||
import { Resend } from 'resend';
|
import { Resend } from "resend";
|
||||||
import type { z } from 'zod';
|
import type { z } from "zod";
|
||||||
|
|
||||||
import { type TemplateKey, type Templates, templates } from './emails';
|
import { type TemplateKey, type Templates, templates } from "./emails";
|
||||||
|
|
||||||
const FROM = 'hello@openpanel.dev';
|
const FROM = process.env.EMAIL_SENDER ?? "hello@openpanel.dev";
|
||||||
|
|
||||||
export async function sendEmail<T extends TemplateKey>(
|
export async function sendEmail<T extends TemplateKey>(
|
||||||
template: T,
|
template: T,
|
||||||
options: {
|
options: {
|
||||||
to: string | string[];
|
to: string | string[];
|
||||||
data: z.infer<Templates[T]['schema']>;
|
data: z.infer<Templates[T]["schema"]>;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const { to, data } = options;
|
const { to, data } = options;
|
||||||
@@ -18,7 +18,7 @@ export async function sendEmail<T extends TemplateKey>(
|
|||||||
const props = schema.safeParse(data);
|
const props = schema.safeParse(data);
|
||||||
|
|
||||||
if (props.error) {
|
if (props.error) {
|
||||||
console.error('Failed to parse data', props.error);
|
console.error("Failed to parse data", props.error);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ export async function sendEmail<T extends TemplateKey>(
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to send email', error);
|
console.error("Failed to send email", error);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user