sending SMTP mail with Jade template
-
create keystone project using yo keystone, and do not choose email feature.
-
install keystone-enmailer
npm install git+https://[email protected]/enraiser/keystone-enmailer.git
-
In keystone.js at keystone.init add email template
keystone.init({ ... 'emails': 'templates/emails', });
-
add globals in .env file
SMTP_HOST=us2.smtp.mailhostbox.com' SMTP_PORT=587 [email protected] SITE_EMAIL_PASSWD=*********
-
create welcome.jade in templates/emails folder
block body-contents h1 Hi #{first_name}, p.text-larger We would like to verify your EmailID to enroll you on #{brand}. p.text-larger click a(href='#{link}') strong this link | to complete this verification.
-
now wherever you want to send mail add this code
var enmailer('keystone-enmailer'); var Email = new keystone.Email('welcome'); var brand = keystone.get('brand'); Email.send({ mandrill: enmailer.mandrill, first_name: 'Sachin Sharma', link: "action/verify?user_id=" +newUser._id, subject: 'Please verify your email', to: "[email protected]", from: { name:brand, email: process.env.SITE_EMAIL_ADDRESS } });