-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodice.js
49 lines (40 loc) · 1.38 KB
/
Codice.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
42
43
44
45
46
47
48
49
/**
* Check spam from linked account and notify master account if there's something to check in Spam Folder :)
*
*/
function checkSpamFolder() {
let mustGo = '';
// Get the threads in the spam folder
var threads = GmailApp.search('in:spam');
// Prepare an email body
var emailBody = '';
// Check if there are any threads in the spam folder
if (threads.length > 0) {
emailBody = 'Spam messages:\n\n';
// Iterate over each thread
for (var i = 0; i < threads.length; i++) {
// Get the messages in this thread
var messages = threads[i].getMessages();
// Iterate over each message
for (var j = 0; j < messages.length; j++) {
// Extract the subject, date, and sender of the message
var subject = messages[j].getSubject();
var date = messages[j].getDate();
var sender = messages[j].getFrom();
// Add the subject, date, and sender to the email body
emailBody += 'Subject: ' + subject + '\n';
emailBody += 'Date: ' + date + '\n';
emailBody += 'Sender: ' + sender + '\n\n';
}
}
mustGo = 'go';
} else {
emailBody = 'No message in spam';
}
// Get the email address of the account owner
var emailAddress = Session.getActiveUser().getEmail();
// Send an email to the account owner
if (mustGo == 'go'){
GmailApp.sendEmail(emailAddress, 'Spam Report', emailBody);
};
}