Files
classroomio/apps/dashboard/src/defer/sendEmail.ts
T

47 lines
989 B
TypeScript
Raw Normal View History

2024-02-29 06:32:40 +00:00
import { defer } from '@defer/client';
import { withEmailTemplate } from '../lib/utils/services/notification/template';
import { getTransporter } from '../lib/utils/services/notification/send';
const sendEmail = async ({
from,
to,
subject,
content,
isPersonalEmail,
replyTo
}: {
from?: string;
to: string;
subject: string;
content: string;
isPersonalEmail?: boolean;
replyTo?: string;
}) => {
try {
const transporter = await getTransporter(isPersonalEmail);
if (!transporter) {
return;
}
const info = await transporter.sendMail({
from: from || '"Best from ClassroomIO" <best@classroomio.com>', // sender address
to, // list of receivers
subject, // Subject line
replyTo,
html: withEmailTemplate(content) // html body
});
console.log('Message sent: %s', info.messageId);
return info;
} catch (error) {
console.error({ error });
return error;
}
};
export default defer(sendEmail);