-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
37 lines (33 loc) · 1 KB
/
index.ts
File metadata and controls
37 lines (33 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { AzureFunction, Context } from '@azure/functions';
import { Resend } from 'resend';
import { render } from '@react-email/components';
import { RESEND_API_KEY, RESEND_FROM_EMAIL } from '../constants';
import { getEmailTemplate, templateNameExists } from '../utils';
interface EmailMessage {
templateName: string;
to: string;
subject: string;
}
const qTSendEmail: AzureFunction = async function (
context: Context,
emailMessage: EmailMessage,
): Promise<void> {
const { templateName, to, subject } = emailMessage;
if (!templateNameExists(templateName)) {
context.log.error(`Invalid Template Name: ${templateName}`);
return;
}
try {
const emailHtml = await render(getEmailTemplate(templateName));
const resend = new Resend(RESEND_API_KEY);
resend.emails.send({
to: to,
from: RESEND_FROM_EMAIL,
subject: subject,
html: emailHtml,
});
} catch (error) {
context.log.error(`qTSendEmail: Failed with error`, error);
}
};
export default qTSendEmail;