Created
August 6, 2014 18:41
-
-
Save kaitwalla/367a24faa596179b94f5 to your computer and use it in GitHub Desktop.
Google Apps Script to send an email from a server that does not have sendmail capabilities. Assumes you're grabbing the text of the email from an external URL as JSON, and including a photo as an attachment
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
// URL to send looks like scriptcontent.google.com/etc/?key=KEY&photo=PHOTO_URL&to=EMAIL_ADDR&subj=SUBJECT&body=URl_FOR_TEXT | |
function doGet(request) { | |
//requiring a key adds security so not just anyone can send mail | |
if (request.parameters.key == 'KEY') { | |
// Get caption from system, make it the body of the email | |
var body = UrlFetchApp.fetch(request.parameters.body); | |
//You can lose this if you're not grabbing JSON | |
var content = JSON.parse(body); | |
// Use "___LB___" in the text to indicate where you want line breaks to be, {B}where you want things bolded{/B} | |
var textContent = content.replace(/___LB___/g,'\n').replace(/\{(\/?)B\}/g,''); | |
var htmlContent = content.replace(/___LB___/g,'<br />').replace(/\{(\/?)B\}/g,'<$1strong>'); | |
var photo = new Array(); | |
photo.push(UrlFetchApp.fetch(request.parameters.photo)); | |
MailApp.sendEmail(request.parameters.to, request.parameters.subj+body.subj, textContent, {htmlBody:htmlContent,attachments:photo}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment