-
Notifications
You must be signed in to change notification settings - Fork 0
/
GAS.js
41 lines (30 loc) · 964 Bytes
/
GAS.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function sendEmailToServer() {
var threads = GmailApp.search('is:unread');
for(var i = 0; i < threads.length; i++){
var messages = threads[i].getMessages();
for(var j =0; j < messages.length; j++)
{
var message = messages[j];
if(message.isUnread()){
var emailData = {
subject: message.getSubject(),
body: message.getPlainBody()
};
var payload = JSON.stringify(emailData);
var options = {
'method': 'post',
'contentType': 'application/json',
'payload': payload
}
UrlFetchApp.fetch('https://d05e-38-75-137-97.ngrok-free.app/forward-email', options);
message.markRead();
}
}
}
}
function createTimeTrigger(){
ScriptApp.newTrigger('sendEmail')
.timeBased()
.everyMinutes(5)
.create();
}