Template issue
Romkin7 opened this issue · 2 comments
Romkin7 commented
I made template and gave all parameters it neede to send it.
but i'm receiving this error all the time:
Error: ENOENT: no such file or directory, open '../../views/email/verifyemail.ejs'
here is my code:
"use strict";
const crypto = require('crypto');
const nodemailer = require('nodemailer');
const mg = require('nodemailer-mailgun-transport');
const ejs = require('ejs');
const auth = {
auth: {
api_key: process.env.MAILGUN_API_KEY,
domain: 'sandbox5454645445454545465656565.mailgun.org'
}
};
const nodemailerMailgun = nodemailer.createTransport(mg(auth));
//Send email to request email confirmation
module.exports.sendActivationEmail = (req, res, user, next) => {
let token = crypto.randomBytes(20).toString("hex");
let contextObject = {
user: user,
token: token
};
nodemailerMailgun.sendMail({
from: 'user 1 <testemail@gmail.com>',
to: user.email, // An array if you have multiple recipients.
subject: 'verify email',
template: {
name: '../../views/email/verifyemail.ejs',
engine: 'ejs',
context: contextObject
}
}, function (err, info) {
if (err) {
console.log('Error: ' + err);
return next();
} else {
console.log('Response: ' + info);
next();
}
});
};
I really don't know where should this verifyemail.ejs file be located so it can be found and sent out.
Cheers, Roman T
jmcdo29 commented
Did you ever figure this out? I'm having a problem with the same thing right now.
EDIT: I was forgetting to add the path "views" to my file. To anyone coming to this looking for help the name of your files should resemble "views/fileNameHere.filetype"
francoism90 commented
Just for the record, if <root>/views/..
is your templates path, use this as name
, e.g.:
name: `views/${template}.pug`,