Last active
February 7, 2017 20:36
-
-
Save abachuk/46429a0e78b369564f3366556341f614 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
// because it's loading through browserify, we're preficing it with npm: | |
import AWS from 'npm:aws-sdk' | |
// It's recommended to keep all your API keys in the environment.js file | |
// and pass them through environment variables | |
import config from '../config/environment'; | |
const ses = new AWS.SES({ | |
apiVersion: '2010-12-01', | |
accessKeyId: config.aws.accessKeyId, | |
"secretAccessKey": config.aws.secretAccessKey, | |
"region": "us-east-1", | |
}); | |
export default Ember.Controller.extend({ | |
actions: { | |
sendContact() { | |
// Grab submitted values | |
const submittedForm = { | |
name: this.get('name'), | |
email: this.get('email'), | |
company: this.get('company'), | |
phone: this.get('phone'), | |
message: this.get('message'), | |
timestamp: new Date().getTime() | |
}; | |
// Prepare values to send with email | |
const emailParams = { | |
Destination: { ToAddresses: [ 'EcmaStack <[email protected]>' ] }, | |
Message: { | |
Body: { Text: { | |
Data: `${submittedForm.name} asks ${submittedForm.message}. You can contact them by email ${submittedForm.email} or phone ${submittedForm.phone}`, | |
Charset: 'UTF-8' } }, | |
Subject: { Data: 'Contact Form', Charset: 'UTF-8' } | |
}, | |
ReplyToAddresses: [submittedForm.email], | |
Source: `${submittedForm.name} <[email protected]>`, // this has to be verified email in SES | |
}; | |
// Save the submitted form to Firebase | |
const newContact = this.store.createRecord('contact', submittedForm); | |
newContact.save().then(function(res) {}); | |
// Send submitted for as email using AWS SES | |
// TODO: handle the error and failure with user friendly messages | |
ses.sendEmail(emailParams, function(error, data) { | |
if (error) { | |
// handle error | |
} else { | |
// handle success | |
} | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment