0
I created the following Model with Nodejs:
'use strict'
function UserDAO(model) {
this.model = model;
}
UserDAO.prototype.email = function(callback) {
//TESTE de email
var filePath = 'services/content/test.html';
var fs = require('fs');
var config = require('config');
var mail = require('../services/email.service');
//TESTE de email
fs.readFile(filePath, function (err, content)
{
if (err) {
console.log('Failed to read email file template html, err = ' + err);
callback('Failed to read email file template html, err = ' + err);
}
else {
var url = config.get('smtpConfig.redirectUrl') + '/#/novo-usuario?token=' + '123456'
var rendered = content.toString().replace('#link#', 'teste.com.br');
mail.send('[email protected]',
'Bem-vindo',
'Acesse o link: ',
rendered, function (err, info)
{
if (err) {
console.log(err);
callback(err)
}
else {
console.log('E-Mail enviado: ' + info);
var retorno = { message: 'Usuário criado com sucesso!' };
callback(null, retorno);
}
});
}
});
//FIM TESTE email
}
module.exports = function(mongoose) {
var User = mongoose.model('User', {
name: {type: String, required: true},
username: {type: String, required: true},
password: {type: String, required: true},
email: {type: String, required: true},
ra: {type: Number, required: false},
tipo: {type: String, required: true}
});
return new UserDAO(User);
}
The email.service is as follows:
var nodemailer = require("nodemailer"); //para enviar emails
var smtpTransport = require('nodemailer-smtp-transport');
var config = require('config');
function enviarEmail (to, subject, text, html, callback) {
//console.log("entrou no email.service.js");
var transporter = nodemailer.createTransport(smtpTransport({
host: config.get('smtpConfig.host'),
port: config.get('smtpConfig.port'),
secure: config.get('smtpConfig.secure'),
auth: {
user: config.get('smtpConfig.auth.user'),
pass: config.get('smtpConfig.auth.pass')
}
}));
// setup e-mail data with unicode symbols
var mailOptions = {
from: config.get('smtpConfig.from'),
to: to,
subject: subject,
text: text,
html: html
};
//verify connection configuration
transporter.verify(function(error, success) {
if (error) {
console.log(error);
transporter.close();
} else {
console.log('Server is ready to take our messages');
//send mail with defined transport object
transporter.sendMail(mailOptions, function (error, info)
{
if (error) {
return callback(error);
}
callback(null, info);
});
}
});
}
exports.send = function (to, subject, text, html, callback) {
return enviarEmail(to, subject, text, html, callback);
}
But I get the following mistake:
Server is ready to take our messages { [Error: Mail command failed: 553 From address not verified ] code: 'EENVELOPE', Sponse: '553 From address not verified - responseCode: 553 } { [Error: Mail command failed: 553 From address not verified] code: 'EENVELOPE', Sponse: '553 From address not verified, responseCode: 553 }