Last active
January 29, 2017 22:31
-
-
Save harryfk/4b31f27e7578efe7d7186f0df2fd3afb 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
// this is a Google Apps script which fetches a random gif from Giphy and then sends it via email to people | |
function sendMail(){ | |
var url = "http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=thanks"; | |
var response = UrlFetchApp.fetch(url, {}).getContentText(); | |
response = JSON.parse(response); | |
var subject = 'Your friendly time tracking reminder.'; | |
var body = 'Please, would you track your time today? It only takes five minutes.\n\n '; | |
var sender = 'Annoying Harry'; | |
var attachmentId = fetchImageToDrive(response.data.image_original_url) | |
var file = DriveApp.getFileById(attachmentId); | |
GmailApp.sendEmail('[email protected]', subject, body, { name: sender, attachments: [file.getAs(MimeType.GIF)] }); | |
GmailApp.sendEmail('[email protected]', subject, body, { name: sender, attachments: [file.getAs(MimeType.GIF)] }); | |
// … | |
function fetchImageToDrive(imageUrl){ | |
var imageBlob = UrlFetchApp.fetch(imageUrl).getBlob(); | |
var image = DriveApp.createFile(imageBlob); | |
image.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.VIEW); | |
return image.getId(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment