Skip to content

Instantly share code, notes, and snippets.

@hugozap
Created July 2, 2013 21:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugozap/5913127 to your computer and use it in GitHub Desktop.
Save hugozap/5913127 to your computer and use it in GitHub Desktop.
Node common snippets
/* common nodejs operations*/
/*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