Add Nodemailer and Mailgun option for contact form

This commit is contained in:
Lee Munroe
2014-02-10 13:32:38 -08:00
parent 55a99318bf
commit c46c321978
4 changed files with 27 additions and 9 deletions

View File

@@ -1,5 +1,17 @@
var secrets = require('../config/secrets');
var sendgrid = require('sendgrid')(secrets.sendgrid.user, secrets.sendgrid.password);
var nodemailer = require("nodemailer");
var smtpTransport = nodemailer.createTransport("SMTP", {
service: "Mailgun",
auth: {
user: secrets.mailgun.login,
pass: secrets.mailgun.password
}
// service: "Sendgrid",
// auth: {
// user: secrets.sendgrid.user,
// pass: secrets.sendgrid.password
// }
});
/**
* GET /contact
@@ -14,7 +26,7 @@ exports.getContact = function(req, res) {
/**
* POST /contact
* Send a contact form via SendGrid.
* Send a contact form via Nodemailer.
* @param email
* @param name
* @param message
@@ -38,14 +50,14 @@ exports.postContact = function(req, res) {
var to = 'you@email.com';
var subject = 'API Example | Contact Form';
var email = new sendgrid.Email({
var mailOptions = {
to: to,
from: from,
subject: subject,
text: body + '\n\n' + name
});
};
sendgrid.send(email, function(err) {
smtpTransport.sendMail(mailOptions, function(err) {
if (err) {
req.flash('errors', { msg: err.message });
return res.redirect('/contact');