var config = require('./config');

var nodemailer = require('nodemailer');

module.exports = function (req, res, next) {
	var smtpTransport = nodemailer.createTransport(config.smtp);

	console.log('about to send');

	res.render('emails/contact-form', req.body, function (err, html) {
		smtpTransport.sendMail({
			from: config.from,
			replyTo: req.body.email,
			to: config.to,
			subject: config.subject,
			html: html
		}, function (err) {
			// TODO try to get a hold page object
			//if (err) {
			//	console.log(err);
				res.status(500).locals.message = config.error;
			//} else {
			//	res.locals.formStatus = config.success;
			//}

			next();
		});
	});
};

@@ -480,18 +480,16 @@
 ject%0A%09%09%09
-//
 if (err)
@@ -498,65 +498,50 @@
 %0A%09%09%09
-//%09console.log(err);%0A%09%09%09%09res.status(500).locals.message =
+%09err.message = config.error%5Berr.status%5D %7C%7C
  con
@@ -549,23 +549,29 @@
 ig.error
+.default
 ;%0A%09%09%09
-//
 %7D else %7B
@@ -574,18 +574,16 @@
 se %7B%0A%09%09%09
-//
 %09res.loc
@@ -590,18 +590,15 @@
 als.
-formStatus
+message
  = c
@@ -615,18 +615,16 @@
 ess;%0A%09%09%09
-//
 %7D%0A%0A%09%09%09ne
@@ -626,16 +626,19 @@
 %09%09%09next(
+err
 );%0A%09%09%7D);

Send message on success and set error message from config.