Skip to content

Instantly share code, notes, and snippets.

@sumitpatel93
Created September 15, 2022 14:03
Show Gist options
  • Save sumitpatel93/4560cb3760e99e0f2a63497dc51d04bf to your computer and use it in GitHub Desktop.
Save sumitpatel93/4560cb3760e99e0f2a63497dc51d04bf to your computer and use it in GitHub Desktop.
sendEmail = async (orgId: string): Promise<void> => {
const transporter = nodemailer.createTransport({
host: 'smtp.office365.com',
port: 587,
secure: false,
auth: {
user: '***',
pass: '***',
},
});
const email = new Email({
send: true,
message: {
from: process.env.EMAIL_SENDER,
},
transport: transporter,
render: (view, locals) => {
return new Promise((resolve, reject) => {
const emailTemplateModel = getEmailTemplateModel(orgId);
emailTemplateModel.findOne({name: 'template'},
async (err: unknown, template: unknown) => {
if (err) {
reject(err); return;
}
if (template) {
let html = ejs.render(template.templateBody, locals);
html = await email.juiceResources(html);
resolve(html);
}
});
});
},
});
email.send({
template: 'mars',
message: {
to: '[email protected]',
},
// locals: {
// name: 'John Smith',
// },
})
.then((e) => {
console.log(e);
return true;
})
.catch((e) => {
console.log(e);
return false;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment