feat: move all email to defer queue #185
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
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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" <[email protected]>', // 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);
|
||||
@@ -0,0 +1,42 @@
|
||||
import { defer } from '@defer/client';
|
||||
|
||||
import { withEmailTemplate } from '../lib/utils/services/notification/template';
|
||||
import { getTransporter } from '../lib/utils/services/notification/send';
|
||||
|
||||
// Send multiple emails
|
||||
const sendEmails = async (
|
||||
emailParams: {
|
||||
from?: string;
|
||||
to: string;
|
||||
subject: string;
|
||||
content: string;
|
||||
isPersonalEmail?: boolean;
|
||||
replyTo?: string;
|
||||
}[]
|
||||
) => {
|
||||
for (const emailParam of emailParams) {
|
||||
const { from, to, subject, content, isPersonalEmail, replyTo } = emailParam;
|
||||
|
||||
try {
|
||||
const transporter = await getTransporter(isPersonalEmail);
|
||||
|
||||
if (!transporter) {
|
||||
return;
|
||||
}
|
||||
|
||||
const info = await transporter.sendMail({
|
||||
from: from || '"Best from ClassroomIO" <[email protected]>', // sender address
|
||||
to, // list of receivers
|
||||
subject, // Subject line
|
||||
replyTo,
|
||||
html: withEmailTemplate(content) // html body
|
||||
});
|
||||
|
||||
console.log('Message sent: %s', info.messageId);
|
||||
} catch (error) {
|
||||
console.error({ error });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default defer(sendEmails);
|
||||
Reference in New Issue
Block a user