Created
September 9, 2014 13:06
-
-
Save martyndavies/aee8611d2b0108ead29d to your computer and use it in GitHub Desktop.
not-so-big-function.js
This file contains 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
function replyWithCard(email, callback){ | |
var cardEmail = new sendgrid.Email({ | |
to: email, | |
from: process.env.FROM_ADDRESS, | |
fromname: process.env.FROM_NAME, | |
subject: process.env.SUBJECT, | |
html: '<h2>Thanks for requesting a business card!</h2>', // <%body%> tag for text | |
text: 'Thanks for asking for a business card, sorry I didn\'t have any on me!' // <%body%> tag for html | |
}); | |
// Tell SendGrid which template to use, and what to substitute | |
cardEmail.setFilters({"templates": {"settings": {"enabled": 1, "template_id": "325ae5e7-69dd-4b95-b003-b0109f759cfa"}}}); | |
cardEmail.addSubstitution('-from_name-', process.env.FROM_NAME); | |
cardEmail.addSubstitution('-twitter-', process.env.TWITTER); | |
cardEmail.addSubstitution('-from_address-', process.env.FROM_ADDRESS); | |
cardEmail.addSubstitution('-sign_off-', process.env.SIGN_OFF); | |
cardEmail.addSubstitution('-signature-', process.env.SIGNATURE); | |
cardEmail.addSubstitution('-card_image_url-', process.env.CARD_IMAGE_URL); | |
// Send the email | |
sendgrid.send(cardEmail, function(err, json){ | |
if (err) { | |
callback(err); | |
} else { | |
callback(json); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment