Hello!
I use fs.readFile for load mail template. It's work fine in normal
situation. But if domain catch error, I don't read file (more
preciselyfs.readFile don't calls callback)
Controller code:
exports.default = function(req, res){
notExist();
}
debugger code:
if(log_to_mail){
global.controllers.mail.sendMail('debug.html', 'Debug Info',
settings.devMail, {
err: err.message,
stack: err.stack,
url: url
});
}
mailer code:
var fs = require('fs');
function getTemplate(template, params, cb){
console.log(1);
fs.readFile(global.rootDir + '/templates/' + template, 'utf8', function
(err, tpl) {
console.log(2);
if(err){
if(typeof cb == 'function') cb(err,null);
return;
}
console.log(3);
fs.readFile(global.rootDir + '/templates/layout.html', 'utf8',
function (err, layout) {
console.log(4);
if(err){
if(typeof cb == 'function') cb(err,null);
return;
}
tpl = tpl.replace(/\{%(\w+)%\}/g, function(s, key) {
return params[key] || s;
});
if(typeof cb == 'function') cb(err,
layout.replace('{%content%}', tpl));
});
});
}
exports.sendMail = function(template, subject, to, params, cb){
var mailer = require('nodemailer');
//.... settings
var mail = mailer.createTransport("SMTP", options);
getTemplate(template, params, function(err, html){
console.log(123456); // test
if(err){
if(typeof cb == 'function') cb(err, null);
return;
}
var mailOptions = {
from: settings.mailFrom, // sender address
to: to, // list of receivers
subject: subject, // Subject line
html: html
}
mail.sendMail(mailOptions, function(error, response){
console.log(response);
if(typeof cb == 'function') cb(error, response);
});
});
}
If I catch error and try get template then executed only console.log(1) and
after read file return to parent without call calback of fs.readFile.
But if I try to wrap notExist(); to setTimeout then code working fine and
shown all console.log
Can you help me?
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.