Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var ss = SpreadsheetApp.openById('1pjunTjJkdi4IzbZM4IHEn8CiNoBohYRPNRARlVNSSxY');
- var sheet = ss.getSheetByName('Send');
- var log = Logger.log;
- var sleep = Utilities.sleep;
- var range = sheet.getRange;
- //Set to a on Change Trigger, get the value of the ceckbox, if true it initiates SendImageEmail(). (origionally had 5 checkboxes, couldnt be asked to debug LOL)
- function checkBoxes() {
- var boxRange = range('C2').getValue();
- var b = boxRange;
- if (b === true) {
- range('C2').setValue(false);
- SpreadsheetApp.flush();
- sendImageEmail();
- }
- }
- //This runs the URL sent Via WhatsApp, uses a regexepression to take the URL from the JSON contents... This is a 'Helper'.
- function getImageURL() {
- var link = 'https://random.dog/woof.json';
- var jsonURL = UrlFetchApp.fetch(link).getContentText();
- var regEx = /"url":"([^"]*)"/;
- var match = jsonURL.match(regEx);
- // Check if there is a match and get the URL (if matched)
- var finalLink = match ? match[1] : null;
- return finalLink; // Return the URL
- }
- //Initiated from the Checkbox trigger, then uses the helper to grab the URL, inserts this into te email (with of course custom subject and body) Then annoys the f*** out of Carey.
- function sendImageEmail() {
- var imageUrl = getImageURL();
- if (imageUrl) {
- var imageBlob = UrlFetchApp.fetch(imageUrl).getBlob();
- var subject = 'I always Win :)';
- var body = 'Hi Carey, <br/><br/> As Requested, Please find the image of a random dog attached below. <br/><br/> Your Sincerely. The Annoying English Kid you wish you never met!<br/><br/>';
- body += '<div style="width: 100%;">';
- body += '<img src="cid:image" style="width: 100%;" />';
- body += '</div>';
- // Send email with image attachment
- MailApp.sendEmail({
- to: recipient,
- subject: subject,
- body: body,
- htmlBody: body,
- inlineImages: { 'image': imageBlob }
- });
- Logger.log('Email sent with image attachment.');
- } else {
- Logger.log('Unable to fetch image URL.');
- }
- //You're Welcome...
Advertisement
Add Comment
Please, Sign In to add comment