Move from Mandrill to Sendgrid.

This commit is contained in:
Jonathan Cremin 2016-05-01 12:30:46 +01:00
parent edd3a2fc54
commit f9210edfc6
3 changed files with 28 additions and 40 deletions

View file

@ -5,7 +5,7 @@
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"engines": { "engines": {
"node": "^5.10.0", "node": "^6.0.0",
"npm": "^3.8.5" "npm": "^3.8.5"
}, },
"scripts": { "scripts": {
@ -51,17 +51,17 @@
"koa-statsd": "~0.0.2", "koa-statsd": "~0.0.2",
"koa-views": "~3.1.0", "koa-views": "~3.1.0",
"koa-websocket": "~1.1.0", "koa-websocket": "~1.1.0",
"mandrill-api": "~1.0.45",
"mime-types": "~2.1.5", "mime-types": "~2.1.5",
"moment": "~2.10.6", "moment": "~2.10.6",
"mongodb-promisified": "~1.0.3", "mongodb-promisified": "~1.0.3",
"node-fetch": "^1.3.2", "node-fetch": "^1.3.2",
"node-sass": "~3.3.0", "node-sass": "~3.6.0",
"node-uuid": "~1.4.3", "node-uuid": "~1.4.3",
"passwords": "~1.3.0", "passwords": "~1.3.0",
"raven": "~0.8.1", "raven": "~0.8.1",
"redis": "~1.0.0", "redis": "~1.0.0",
"s3-upload-stream": "~1.0.7", "s3-upload-stream": "~1.0.7",
"sendgrid": "^2.0.0",
"statsy": "~0.2.0", "statsy": "~0.2.0",
"stripe": "~3.7.1", "stripe": "~3.7.1",
"swig": "~1.4.2" "swig": "~1.4.2"

View file

@ -5,8 +5,8 @@ import views from 'co-views';
const render = views(__dirname + '/../views', { default: 'ejs'}); const render = views(__dirname + '/../views', { default: 'ejs'});
import debugname from 'debug'; import debugname from 'debug';
const debug = debugname('hostr-web:auth'); const debug = debugname('hostr-web:auth');
import { Mandrill } from 'mandrill-api/mandrill'; import sendgridInit from 'sendgrid';
const mandrill = new Mandrill(process.env.MANDRILL_KEY); const sendgrid = sendgridInit(process.env.SENDGRID_KEY);
export function* authenticate(email, password) { export function* authenticate(email, password) {
const Users = this.db.Users; const Users = this.db.Users;
@ -102,20 +102,16 @@ ${process.env.WEB_BASE_URL + '/activate/' + user.activationCode}
Jonathan Cremin, Hostr Founder Jonathan Cremin, Hostr Founder
`; `;
mandrill.messages.send({message: { const mail = new sendgrid.Email({
to: user.email,
from: 'jonathan@hostr.co',
fromname: 'Jonathan from Hostr',
html: html, html: html,
text: text, text: text,
subject: 'Welcome to Hostr', subject: 'Welcome to Hostr',
'from_email': 'jonathan@hostr.co', });
'from_name': 'Jonathan from Hostr', mail.addCategory('activate');
to: [{ sendgrid.send(mail);
email: user.email,
type: 'to',
}],
'tags': [
'user-activation',
],
}});
} }
@ -134,20 +130,16 @@ export function* sendResetToken(email) {
const text = `It seems you've forgotten your password :( const text = `It seems you've forgotten your password :(
Visit ${process.env.WEB_BASE_URL + '/forgot/' + token} to set a new one. Visit ${process.env.WEB_BASE_URL + '/forgot/' + token} to set a new one.
`; `;
mandrill.messages.send({message: { const mail = new sendgrid.Email({
to: user.email,
from: 'jonathan@hostr.co',
fromname: 'Jonathan from Hostr',
html: html, html: html,
text: text, text: text,
subject: 'Hostr Password Reset', subject: 'Hostr Password Reset',
'from_email': 'jonathan@hostr.co', });
'from_name': 'Jonathan from Hostr', mail.addCategory('password-reset');
to: [{ sendgrid.send(mail);
email: user.email,
type: 'to',
}],
'tags': [
'password-reset',
],
}});
} else { } else {
throw new Error('There was an error looking up your email address.'); throw new Error('There was an error looking up your email address.');
} }

View file

@ -3,8 +3,8 @@ import views from 'co-views';
const render = views(path.join(__dirname, '/../views'), { default: 'ejs'}); const render = views(path.join(__dirname, '/../views'), { default: 'ejs'});
import Stripe from 'stripe'; import Stripe from 'stripe';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY); const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
import { Mandrill } from 'mandrill-api/mandrill'; import sendgridInit from 'sendgrid';
const mandrill = new Mandrill(process.env.MANDRILL_KEY); const sendgrid = sendgridInit(process.env.SENDGRID_KEY);
const fromEmail = process.env.EMAIL_FROM; const fromEmail = process.env.EMAIL_FROM;
const fromName = process.env.EMAIL_NAME; const fromName = process.env.EMAIL_NAME;
@ -48,20 +48,16 @@ export function* create() {
Jonathan Cremin, Hostr Founder Jonathan Cremin, Hostr Founder
`; `;
mandrill.messages.send({message: { const mail = new sendgrid.Email({
to: this.session.user.email,
from: fromEmail,
fromname: fromName,
html: html, html: html,
text: text, text: text,
subject: 'Hostr Pro', subject: 'Hostr Pro',
'from_email': fromEmail, });
'from_name': fromName, mail.addCategory('pro-upgrade');
to: [{ sendgrid.send(mail);
email: this.session.user.email,
type: 'to',
}],
'tags': [
'pro-upgrade',
],
}});
} }
export function* cancel() { export function* cancel() {