Skip to content

Instantly share code, notes, and snippets.

@taylorstine
Last active February 17, 2016 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save taylorstine/d280d5ddcad665fba595 to your computer and use it in GitHub Desktop.
Save taylorstine/d280d5ddcad665fba595 to your computer and use it in GitHub Desktop.
emailSender function for parse-server
import aws from 'aws-sdk'
import path from 'path'
import fs from 'fs'
aws.config.loadFromPath(path.resolve('credentials', 'aws_config.json'));
const ses = new aws.SES({apiVersion: '2010-12-01'});
const resetEmail = fs.readFileSync(path.resolve('emails', 'reset-password.html'), 'utf8');
const verifyEmail = fs.readFileSync(path.resolve('emails', 'verify-email.html'), 'utf8');
import {Constants} from 'parse-server'
import Promise from 'bluebird'
export function sendEmail(type:string, link:string, email:string):Promise {
let emailContent:?string = null;
let subject:?string = null;
switch (type) {
case Constants.RESET_PASSWORD:
emailContent = resetEmail.replace('<%LINK_GOES_HERE%>', link);
subject = "Reset App password";
break;
case Constants.VERIFY_EMAIL:
emailContent = verifyEmail.replace('<%LINK_GOES_HERE%>', link);
subject = "Verify App email";
break;
default:
throw new Error("Invalid email type: " + type)
}
return new Promise((resolve, reject)=>{
ses.sendEmail({
Source: 'contact@app.com',
Destination: {
ToAddresses: [email]
},
Message: {
Subject: {
Data: subject
},
Body: {
Html : {
Data: emailContent,
Charset: "UTF-8"
}
}
}
}, function(err) {
if (err) {
throw new Error("Error sending email ", err);
return reject(err);
}
resolve();
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment