Skip to content

Instantly share code, notes, and snippets.

@martyndavies
Last active January 2, 2016 17:09
Show Gist options
  • Save martyndavies/8335169 to your computer and use it in GitHub Desktop.
Save martyndavies/8335169 to your computer and use it in GitHub Desktop.
Parse.Cloud.define("sendEmail", function(request, response) {
var sendgrid = require("sendgrid");
sendgrid.initialize("your_sendgrid_username", "your_sendgrid_password");
var name = request.params.name;
var email = request.params.email;
var message = request.params.message;
sendgrid.sendEmail({
to: "youremail@yourdomain.com",
from: email,
fromname: name,
subject: "Email from my website",
text: "Name: "+name+"\nEmail: "+email+"\nMessage:\n\n"+message
}, {
success: function(httpResponse) {
console.log(httpResponse);
response.success("Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
response.error("Uh oh, something went wrong");
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment