Created
July 2, 2013 21:06
-
-
Save hugozap/5913127 to your computer and use it in GitHub Desktop.
Node common snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* common nodejs operations*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Fragmento para enviar email: | |
Modulos requeridos: | |
var SendGrid = require('sendgrid').SendGrid; | |
var nodemailer = require("nodemailer"); | |
*/ | |
var sendEmail = function(emailInfo,settings){ | |
var smtpTransport = nodemailer.createTransport("SMTP",{ | |
service: "SendGrid", | |
auth: { | |
user: settings.emailServerUser, | |
pass: settings.emailServerPassword | |
} | |
}); | |
// setup e-mail data with unicode symbols | |
var mailOptions = { | |
from: settings.sentEmailFrom, // sender address | |
to: emailInfo.sendToEmail, // list of receivers | |
subject: emailInfo.subject, // Subject line | |
html: emailInfo.body// html body | |
} | |
// send mail with defined transport object | |
smtpTransport.sendMail(mailOptions, function(error, response){ | |
if(error){ | |
console.log(error); //MANEJAR ERROR AQUI | |
}else{ | |
console.log("Message sent: " + response.message); | |
} | |
// if you don't want to use this transport object anymore, uncomment following line | |
//smtpTransport.close(); // shut down the connection pool, no more messages | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment