我有一个运行Node的API服务器和以下添加用户功能:
add: function (userArray, onSuccess, onError) {
userArray.forEach(function (user) {
var length = 8,
charset = "abcdefghijklnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
retVal = "";
for (var i = 0, n = charset.length; i < length; ++i) {
retVal += charset.charAt(Math.floor(Math.random() * n));
}
var password = retVal;
var salt = bcrypt.genSaltSync(10);
var password = bcrypt.hashSync(password, salt);
user.user_type_id = user.user_type.id;
if (user.title) {
user.title_id = user.title.id;
}
user.division_id = user.division.id;
user.password = password;
user.user_password = retVal;
user.image_path = 'img/AdamProfil.png';
});
emailTemplates(templatesDir, function (err, template) {
if (err) {
console.log(err);
} else {
var transportBatch = nodemailer.createTransport(smtpTransport({
host: 'smtp.mail.dk',
secureConnection: true,
port: 587,
tls: {
rejectUnauthorized: false
},
auth: {
user: 'my@mail.com',
pass: 'myPassword'
}
}));
var Render = function(locals) {
this.locals = locals;
this.send = function(err, html, text) {
if (err) {
console.log(err);
} else {
transportBatch.sendMail({
from: '*** <support@mymail.dk>',
to: locals.username,
subject: 'Din adgangskode til ***!',
html: html,
// generateTextFromHTML: true,
text: text
}, function(err, responseStatus) {
if (err) {
console.log(err);
} else {
console.log(responseStatus.message);
}
});
}
};
this.batch = function(batch) {
batch(this.locals, templatesDir, this.send);
};
};
// Send multiple emails
template('password', true, function(err, batch) {
for(var user in userArray) {
var render = new Render(userArray[user]);
render.batch(batch);
}
});
}
});
userArray.forEach(function(user){
User.create(user)
.then(function(createdUser) {
user.profile.user_id = createdUser[null];
Profile.create(user.profile);
});
});
onSuccess(userArray);
}
现在当我使用控制台编写server.js
来运行我的node server.js
文件并运行此函数时,它正确地向目标发送了一封电子邮件(SUCCESS!?)no,因为当我使用{{1并使用完全相同的参数运行完全相同的函数,不发送电子邮件。
到底是怎么回事?:)
答案 0 :(得分:1)
仅查看代码,我看到ignorenonframetext
变量。当你使用templatesDir
跑步时,我猜这是不同的,或以意想不到的方式改变。
永远查看this issue。你有没有引用绝对路径,或forever
?
值得一试,祝你好运!