I have been breaking head for some time trying to create a page of contacts where the user through the page can send an email. I am new with node and so I have had some problems. At the moment I can not get my application to recognize nodemailer and I'm having the following error message:
Uncaught Error: Module name "nodemailer" has not been loaded yet for context: _. Use require ([])
Follow my code for analysis. Please help me, I have gone through several tutorials and forums but I can not 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);
};