1
0
Fork 0

switch to mailgun for mails, READ THE README, breaking changes (backup config.js)

2015
Jérôme Loï 10 years ago
parent ba3ce92191
commit 2e21d2ec31

1
.gitignore vendored

@ -17,4 +17,5 @@ results
node_modules node_modules
html/assets/js/email* html/assets/js/email*
/config.json /config.json
config.js

@ -1,3 +1,7 @@
# SquatConf website. # SquatConf website.
```cp config-sample.js config.js```
edit congif with the mailgun api key
```npm i && npm start``` ```npm i && npm start```

@ -6,11 +6,12 @@ module.exports = require('rc')(name, {
db_opts: { valueEncoding: 'json' } db_opts: { valueEncoding: 'json' }
, db_path: join(cwd, 'db', name) , db_path: join(cwd, 'db', name)
, port: 8000 , port: 8000
, host: "http://test.squatconf.eu" , host: 'http://test.squatconf.eu'
, mailjetKey: 'key-...'
, email: { , email: {
from : "no-reply@squatconf.eu" from : 'no-reply@squatconf.eu'
, subject : "Hello, everyone is welcome at SquatConf.." , subject : 'Hello, everyone is welcome at SquatConf..'
, bodyText : "Please verify that you wish to signup by following this link\n%link%\nYou can ignore this message if you DID NOT request to signup at our website\nhttp://squatconf.eu\n\nThe next event is in Paris, we hope to see you there !!\n\nKind regards from the team,\nSquatConf Paris 2014" , bodyText : 'Please verify that you wish to signup by following this link\n%link%\nYou can ignore this message if you DID NOT request to signup at our website\nhttp://squatconf.eu\n\nThe next event is in Paris, we hope to see you there !!\n\nKind regards from the team,\nSquatConf Paris 2014'
} }
}) })

@ -28,7 +28,7 @@
"ecstatic": "^0.5.4", "ecstatic": "^0.5.4",
"level": "^0.18.0", "level": "^0.18.0",
"load-svg": "^1.0.0", "load-svg": "^1.0.0",
"nodemailer": "^1.3.0", "mailgun": "^0.5.0",
"rc": "^0.5.1", "rc": "^0.5.1",
"stack": "^0.1.0", "stack": "^0.1.0",
"tiny-route": "^2.1.1", "tiny-route": "^2.1.1",

@ -18,6 +18,7 @@ if(!fs.existsSync(config.db_path)){
}); });
} }
stack.errorHandler = function error(req, res, err) { stack.errorHandler = function error(req, res, err) {
res.statusCode = 302 res.statusCode = 302
res.setHeader('Location', '/') res.setHeader('Location', '/')

@ -2,6 +2,11 @@ var sanitize = require('xss-escape')
, rn = require('./rng') , rn = require('./rng')
, ip = require('./ip-trace') , ip = require('./ip-trace')
, config = require('../config') , config = require('../config')
, Mailgun = require('mailgun').Mailgun
, mg = new Mailgun(config.mailjetKey);
module.exports = function(db) { module.exports = function(db) {
return function (req, res, next) { return function (req, res, next) {
@ -33,29 +38,34 @@ module.exports = function(db) {
if (err) return error(err) if (err) return error(err)
// db write OK.. // db write OK..
var nodemailer = require('nodemailer') var url = config.host +'/confirm'
, transporter = nodemailer.createTransport()
, url = config.host +'/confirm'
, qstr = '?email='+ email +'&token='+ obj.token , qstr = '?email='+ email +'&token='+ obj.token
, link = url + qstr +'\n\n' , link = url + qstr +'\n\n'
, opts = {
var opts = {
from : config.email.from from : config.email.from
, to : email , to : email
, subject: config.email.subject , subject: config.email.subject
, text : config.email.bodyText.replace(/\%link\%/, link) , text : config.email.bodyText.replace(/\%link\%/, link)
} }
transporter.sendMail(opts, function(err, data) { mg.sendText(
if (err) return error(err) opts.from
, email
// validation email sent , opts.subject
console.log('email sent..', opts) , opts.text
, {}
, function(err) {
if (err) console.log('Guru meditation: ' + err);
else{
res.statusCode = 302 res.statusCode = 302
res.setHeader('Location', '/') res.setHeader('Location', '/')
console.log('email sent..', opts)}
return res.end() return res.end()
}) });
}) })
} else { } else {

Loading…
Cancel
Save