fix: use relative part for defer func #185 chore: move sendEmail into defer fix: remove anon function to defer #185 feat: implement batch email sending with defer.run #185 chore: debug sendEmails #185 chore: add robots.txt chore: use promise.all in sendEmails chore: debug defer sendEmails #185 chore: try defer sendEmail without loop #105 chore: comment code chore: change loop style #185 chore: use promise.all for vercel edge #185 feat: add await to sendEmailNotification #185 chore: use sendEmails #185 fix: debug sendEmails #185 fix: email not updating in LMS fix: remove early return in sendEmails #185
47 lines
989 B
TypeScript
47 lines
989 B
TypeScript
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);
|