-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBACKUP_EMAIL_SCRIPT.js
More file actions
104 lines (92 loc) · 3.58 KB
/
Copy pathBACKUP_EMAIL_SCRIPT.js
File metadata and controls
104 lines (92 loc) · 3.58 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
============================================================
HACKAURA 2026 - BACKUP EMAIL SCRIPT
============================================================
PURPOSE: Email failover - when the primary account's
daily email quota (100) runs out, the main script
calls THIS script to send emails instead.
SETUP INSTRUCTIONS:
============================================================
1. Login to a DIFFERENT Google account (friend/co-organizer)
2. Go to: https://script.google.com
3. Click "+ New Project"
4. Delete everything and paste this ENTIRE script
5. Click "Deploy" → "New Deployment"
6. Settings:
- Type: Web App
- Execute as: Me
- Who has access: Anyone
7. Click "Deploy" → Authorize when prompted
8. Copy the deployment URL
9. Give the URL to the main account owner
That's it! This account now serves as a backup
email sender with its own 100 emails/day quota.
============================================================
*/
function doPost(e) {
try {
var data = JSON.parse(e.postData.contents);
if (data.action === 'sendEmail') {
// Validate required fields
if (!data.to || !data.subject || !data.htmlBody) {
return ContentService.createTextOutput(
JSON.stringify({
result: 'error',
message: 'Missing required fields (to, subject, htmlBody)'
})
).setMimeType(ContentService.MimeType.JSON);
}
// Check this backup account's quota too
var remaining = MailApp.getRemainingDailyQuota();
if (remaining <= 0) {
return ContentService.createTextOutput(
JSON.stringify({
result: 'error',
message: 'Backup quota also exhausted',
remaining: 0
})
).setMimeType(ContentService.MimeType.JSON);
}
// Send the email
MailApp.sendEmail({
to: data.to,
subject: data.subject,
htmlBody: data.htmlBody
});
return ContentService.createTextOutput(
JSON.stringify({
result: 'success',
message: 'Email sent via backup',
remaining: remaining - 1
})
).setMimeType(ContentService.MimeType.JSON);
}
// Health check action
if (data.action === 'checkQuota') {
return ContentService.createTextOutput(
JSON.stringify({
result: 'success',
remaining: MailApp.getRemainingDailyQuota()
})
).setMimeType(ContentService.MimeType.JSON);
}
return ContentService.createTextOutput(
JSON.stringify({ result: 'error', message: 'Unknown action' })
).setMimeType(ContentService.MimeType.JSON);
} catch (err) {
return ContentService.createTextOutput(
JSON.stringify({ result: 'error', message: err.toString() })
).setMimeType(ContentService.MimeType.JSON);
}
}
// Also support GET for quick health checks
function doGet(e) {
var remaining = MailApp.getRemainingDailyQuota();
return ContentService.createTextOutput(
JSON.stringify({
result: 'success',
status: 'Backup email service is running',
remaining: remaining
})
).setMimeType(ContentService.MimeType.JSON);
}