Created
September 15, 2022 14:03
-
-
Save sumitpatel93/4560cb3760e99e0f2a63497dc51d04bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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