在我的存储库文件中,我有以下代码:
`var mailer = require('../helper/mailer');
db.prototype.ForgotPassword =function(req,res,next,exec){
mailer.SendEmail(function(result){
exec({message:result});
});
}`
而且,我的邮件文件包含以下代码,
`var restify = require('restify');
var nodeMailer = require('nodemailer');
var env = process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var config = require('../config/config')[env];
var exports = module.exports = {};
exports.SendEmail = function(callback){
var transporter = nodeMailer.createTransport({
service : 'Gmail',
auth:{
user:config.mailAddress,
pass:config.password
}
});
var mailOptions = {
from: 'prateek@xyz.com',
to: 'prateek@abc.com',
subject: 'xyz',
text: 'Hello world ',
html: '<b>Hello world</b>'
};
mailer.transporter.sendMail(mailOptions, function(error, info){
console.log('sent');
if(error){
callback(error);
}else{
callback('Message sent: ' + info.response);
}
});
}`
但是,当我尝试执行ForgotPassword函数时,它会抛出一个错误,即未定义邮件程序。我陷入了这个问题。如果有人有答案,请帮助我。
问候。