Created
March 15, 2015 17:28
-
-
Save compwron/32f4595a22bc5a61a426 to your computer and use it in GitHub Desktop.
gmail monitor and filesender
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
/* PayPal Shop with Apps Script */ | |
/* Written by Amit Agarwal - ctrlq.org */ | |
/* http://www.labnol.org/internet/sell-digital-products-online/28554/ */ | |
PAYPAL = [ | |
["product-001", "useful-websites-book.pdf"], | |
["product-002", "linux-training-course.mp4"], | |
["product-003", "steve-audio-book.mp3"], | |
["product-004", "presentation-template.ppt"] | |
]; | |
function PayPal() { | |
ScriptApp.newTrigger("myShop").timeBased().everyMinutes(5).create(); | |
} | |
function myShop() { | |
var file, size, files, threads; | |
for (var p in PAYPAL) { | |
threads = GmailApp.search("is:unread from:paypal " + PAYPAL[p][0]); | |
if (threads.length > 0) { | |
files = DriveApp.searchFiles('title contains "' + PAYPAL[p][1] + '"'); | |
if (files.hasNext()) { | |
file = files.next(); | |
size = file.getSize()/(1024*1024); | |
for (var i=0; i<threads.length; i++) { | |
var buyer = threads[i].getMessages()[0].getReplyTo(); | |
var subject = "Thank you for your purchase"; | |
var body = "Please download the file using the link below.\n\n"; | |
if (size > 20) { | |
file.addViewer(buyer); | |
GmailApp.sendEmail(buyer, subject, body + file.getUrl()); | |
} else { | |
GmailApp.sendEmail(buyer, subject, body, {attachments: file.getBlob()}); | |
} | |
threads[i].markRead().moveToArchive(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment