Add Nodemailer and Mailgun option for contact form
This commit is contained in:
@ -59,7 +59,7 @@ Features
|
|||||||
- Rails 3.1-style asset pipeline (See FAQ)
|
- Rails 3.1-style asset pipeline (See FAQ)
|
||||||
- LESS stylesheets (auto-compiled via Express middleware)
|
- LESS stylesheets (auto-compiled via Express middleware)
|
||||||
- Bootstrap 3 + Flat UI + iOS7 Theme
|
- Bootstrap 3 + Flat UI + iOS7 Theme
|
||||||
- Contact Form (powered by Sendgrid)
|
- Contact Form (powered by Mailgun or Sendgrid)
|
||||||
- **Account Management**
|
- **Account Management**
|
||||||
- Gravatar
|
- Gravatar
|
||||||
- Profile Details
|
- Profile Details
|
||||||
@ -203,6 +203,13 @@ Obtaining API Keys
|
|||||||
- Enter your *Domain Name*, then and click **Register**
|
- Enter your *Domain Name*, then and click **Register**
|
||||||
- Copy and paste *Key* into `config.secrets.js`
|
- 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
|
Project Structure
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
@ -1,5 +1,17 @@
|
|||||||
var secrets = require('../config/secrets');
|
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
|
* GET /contact
|
||||||
@ -14,7 +26,7 @@ exports.getContact = function(req, res) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* POST /contact
|
* POST /contact
|
||||||
* Send a contact form via SendGrid.
|
* Send a contact form via Nodemailer.
|
||||||
* @param email
|
* @param email
|
||||||
* @param name
|
* @param name
|
||||||
* @param message
|
* @param message
|
||||||
@ -38,14 +50,14 @@ exports.postContact = function(req, res) {
|
|||||||
var to = 'you@email.com';
|
var to = 'you@email.com';
|
||||||
var subject = 'API Example | Contact Form';
|
var subject = 'API Example | Contact Form';
|
||||||
|
|
||||||
var email = new sendgrid.Email({
|
var mailOptions = {
|
||||||
to: to,
|
to: to,
|
||||||
from: from,
|
from: from,
|
||||||
subject: subject,
|
subject: subject,
|
||||||
text: body + '\n\n' + name
|
text: body + '\n\n' + name
|
||||||
});
|
};
|
||||||
|
|
||||||
sendgrid.send(email, function(err) {
|
smtpTransport.sendMail(mailOptions, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
req.flash('errors', { msg: err.message });
|
req.flash('errors', { msg: err.message });
|
||||||
return res.redirect('/contact');
|
return res.redirect('/contact');
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
"less": "~1.6.2",
|
"less": "~1.6.2",
|
||||||
"mongoose": "~3.8.5",
|
"mongoose": "~3.8.5",
|
||||||
"node-foursquare": "~0.2.0",
|
"node-foursquare": "~0.2.0",
|
||||||
|
"nodemailer": "~0.6.0",
|
||||||
"passport": "~0.2.0",
|
"passport": "~0.2.0",
|
||||||
"passport-facebook": "~1.0.2",
|
"passport-facebook": "~1.0.2",
|
||||||
"passport-github": "~0.1.5",
|
"passport-github": "~0.1.5",
|
||||||
@ -27,7 +28,6 @@
|
|||||||
"passport-oauth": "~1.0.0",
|
"passport-oauth": "~1.0.0",
|
||||||
"passport-twitter": "~1.0.2",
|
"passport-twitter": "~1.0.2",
|
||||||
"request": "~2.33.0",
|
"request": "~2.33.0",
|
||||||
"sendgrid": "~0.4.6",
|
|
||||||
"tumblr.js": "~0.0.4",
|
"tumblr.js": "~0.0.4",
|
||||||
"twit": "~1.1.12",
|
"twit": "~1.1.12",
|
||||||
"underscore": "~1.5.2",
|
"underscore": "~1.5.2",
|
||||||
|
@ -23,4 +23,3 @@ block content
|
|||||||
button.btn.btn-default(type='submit')
|
button.btn.btn-default(type='submit')
|
||||||
i.fa.fa-mail-forward
|
i.fa.fa-mail-forward
|
||||||
| Send
|
| Send
|
||||||
img.pull-right(height='34', src='/img/sendgrid.png')
|
|
||||||
|
Reference in New Issue
Block a user