Skip to content

Commit

Permalink
Merge branch 'leemunroe-add-mailgun'
Browse files Browse the repository at this point in the history
* leemunroe-add-mailgun:
  Removed sendgrid image logo
  JavaScript style formatting. SendGrid as a default service for contact form.
  Add Nodemailer and Mailgun option for contact form
  • Loading branch information
sahat committed Feb 11, 2014
2 parents c6061a7 + 146ef65 commit 1ba87d6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Features
- Rails 3.1-style asset pipeline (See FAQ)
- LESS stylesheets (auto-compiled via Express middleware)
- Bootstrap 3 + Flat UI + iOS7 Theme
- Contact Form (powered by Sendgrid)
- Contact Form (powered by Mailgun or Sendgrid)
- **Account Management**
- Gravatar
- Profile Details
Expand Down Expand Up @@ -218,6 +218,13 @@ Obtaining API Keys
- Enter your *Domain Name*, then and click **Register**
- Copy and paste *Key* into `config/secrets.js`

<hr>

<img src="https://raw.github.com/mailgun/media/master/Mailgun_Primary.png" width="200">
- Go to http://www.mailgun.com
- Sign up and add your *Domain Name*
- From the domain overview, copy and paste the default SMTP *Login* and *Password* into `config.secrets.js`

Project Structure
-----------------

Expand Down
7 changes: 6 additions & 1 deletion config/secrets.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ module.exports = {
localAuth: true,
sessionSecret: "Your Session Secret goes here",

mailgun: {
login: 'Your Mailgun SMTP Username',
password: 'Your Mailgun SMTP Password'
},

sendgrid: {
user: 'Your SendGrid Username',
password: 'Your SendGrid Password'
Expand Down Expand Up @@ -49,7 +54,7 @@ module.exports = {
callbackURL: '/auth/google/callback',
passReqToCallback: true
},

steam: {
apiKey: 'Your Steam API Key'
},
Expand Down
24 changes: 18 additions & 6 deletions controllers/contact.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -35,17 +47,17 @@ exports.postContact = function(req, res) {
var from = req.body.email;
var name = req.body.name;
var body = req.body.message;
var to = 'you@email.com';
var to = 'your@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');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"less": "~1.6.3",
"mongoose": "~3.8.7",
"node-foursquare": "~0.2.0",
"nodemailer": "~0.6.0",
"passport": "~0.2.0",
"passport-facebook": "~1.0.2",
"passport-github": "~0.1.5",
Expand All @@ -27,7 +28,6 @@
"passport-oauth": "~1.0.0",
"passport-twitter": "~1.0.2",
"request": "~2.33.0",
"sendgrid": "~0.4.6",
"tumblr.js": "~0.0.4",
"twit": "~1.1.12",
"underscore": "~1.6.0",
Expand Down
Binary file removed public/img/sendgrid.png
Binary file not shown.
1 change: 0 additions & 1 deletion views/contact.jade
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ block content
button.btn.btn-default(type='submit')
i.fa.fa-mail-forward
| Send
img.pull-right(height='34', src='/img/sendgrid.png')

0 comments on commit 1ba87d6

Please sign in to comment.