Skip to main content

Gmail - Automatically Archive Successfully Processed Emails

Automatically manage successfully processed emails in your Gmail inbox

This guide uses Google Apps Script to check for new emails every minute and automatically:

  • Mark successfully processed emails as read

  • Apply a Caresquare Processed label

  • Archive 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:

  1. Click Run.

  2. The first time you run the script, Google will ask you to authorise it.

  3. Follow the prompts to grant the required Gmail permissions.

  4. Once authorised, click Run again.


Step 5 – Create an Automatic Trigger

To have Gmail automatically process new emails:

  1. Click Triggers in the left-hand sidebar.

  2. Click Add Trigger in the bottom-right corner.

  3. Configure the trigger with the following settings:

Setting

Value

Choose which function to run

moveCaresquareProcessed

Deployment

Head

Event source

Time-driven

Type of time based trigger

Minutes timer

Select minute interval

Every minute

  1. 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 _Caresquare label

    • Mark 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.

Did this answer your question?