-1
I have been racking my brain for some time trying to create a contact page where the user can send an email. I’m new to Ode, and that’s why I’ve been through some trouble. At the moment I can’t get my application to recognize the nodemailer and I’m getting the following error message:
Uncaught Error: Module name "nodemailer" has not been Loaded yet for context: _. Use require([])
Follow my code to analyze. Please help me, I’ve been through several tutorials and forums but I can’t solve the problem.
//CONTROLLER
(function() {
'use strict';
var ContatoController = ['$scope', '$http', function($scope, $http){
$scope.formulario = {};
$scope.formulario.nome;
$scope.formulario.email;
$scope.formulario.assunto;
$scope.formulario.mensagem;
$scope.enviaEmail = function() {
$http({
method: 'POST',
url: '/contact-form',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: {
contactNome: $scope.formulario.nome,
contactEmail: $scope.formulario.email,
contactAssunto: $scope.formulario.assunto,
contactMensagem: $scope.formulario.mensagem
}
})
.success(function(data, status, headers, config) {
console.log("Mensagem enviada com sucesso!");
}).
error(function(data, status, headers, config) {
console.log("Não deu certo.");
});
};
}];
angular.module('contactForm').controller('ContatoController', ContatoController);
})();
//CONTROLLER-SERVER
'use strict';
var nodemailer = require('nodemailer');
app.post('/enviaEmail', function(req, res) {
var transporter = nodemailer.createTransport({
host: 'mail.meudominio.com',
port: '465',
secure: true,
auth: {
user: '[email protected]',
pass: '****'
}
});
exports.enviaEmail = function(req, res) {
var data = req.body;
transporter.enviaEmail({
from: data.contactEmail,
to: '[email protected]',
subject: data.contactAssunto + ' - Enviado por: ' + data.contactNome,
text: data.contactMensagem
});
res.json(data);
};
});
//ROUTES
'use strict';
angular.module('contactForm')
.exports = function(app) {
var core = require('js/server/core.server.controller.js');
app.route('/contact-form').post(core.enviaEmail);
};
What is your version of
Node.js
? You can check the version using the commandnode -v
in hisprompt
– Sorack
The version is V8.12.0.
– Aline Luisa
Have you tried to reinstall your
Node.js
?– Sorack
Was any of the answer helpful? Don’t forget to choose one and mark it so it can be used if someone has a similar question!
– Sorack