This guide uses Google Apps Script to check for new emails every minute and automatically:
Mark successfully processed emails as read
Apply a
Caresquare ProcessedlabelArchive the email
Leave any emails containing errors or requiring action in your inbox
Note: This automation only affects emails sent from [email protected] that contain the text “Successfully processed”.
Step 1 – Open Google Apps Script
Navigate to:
Click New project.
Step 2 – Paste the Script
Delete any existing code in the editor and replace it with the following:
function moveCaresquareProcessed() {
var sender = '[email protected]';
var labelName = '_Caresquare';
var label = GmailApp.getUserLabelByName(labelName) || GmailApp.createLabel(labelName);
var threads = GmailApp.search(`from:${sender} is:unread`);
threads.forEach(thread => {
var messages = thread.getMessages();
var lastMsg = messages[messages.length - 1];
if (!lastMsg.isUnread()) return;
var body = lastMsg.getBody();
if (body.includes('Successfully processed')) {
thread.addLabel(label);
thread.markRead();
thread.moveToArchive();
}
});
}Step 3 – Save the Project
Click the Save project icon (💾) located next to the Run button.
You can give the project a name such as:
Caresquare Inbox Management
Step 4 – (Optional) Process Existing Emails
If you’d like the rule to immediately organise any existing Caresquare emails already in your inbox:
Click Run.
The first time you run the script, Google will ask you to authorise it.
Follow the prompts to grant the required Gmail permissions.
Once authorised, click Run again.
Step 5 – Create an Automatic Trigger
To have Gmail automatically process new emails:
Click Triggers in the left-hand sidebar.
Click Add Trigger in the bottom-right corner.
Configure the trigger with the following settings:
Setting | Value |
Choose which function to run |
|
Deployment |
|
Event source |
|
Type of time based trigger |
|
Select minute interval |
|
Click Save.
What Happens Next?
Every minute, Google Apps Script will:
Look for new unread emails from [email protected]
Check whether the email contains “Successfully processed”
If it does:
Add the
_CaresquarelabelMark the email as read
Archive it automatically
Any emails that do not contain “Successfully processed” (such as validation errors or invoices requiring attention) will remain in your inbox so you can review them.
Frequently Asked Questions
Will this delete my emails?
No. Emails are only archived, not deleted. They remain searchable in Gmail and can be found under All Mail or by selecting the _Caresquare label.
Can I undo this later?
Yes. Simply remove the trigger or delete the Apps Script project to stop the automation. Existing archived emails can be moved back to your inbox at any time.
Does this affect other emails?
No. The script only checks unread emails sent from [email protected]. Other emails in your Gmail account are not affected.
