10 best Google scripts to automate Gmail

Gmail is not only the online interface for sending and receiving e-mail from a Google Mail account but it is also a fantastic client for any address or account, as a very powerful and complete web application.
We have already seen how it is possible to import and manage other Email accounts in Gmail without problems.
The internal options and tools of Gmail are many and are accessible, almost all, from the gear menu at the top right.
In this article we go a little further and see the best scripts that can be applied to Gmail to automate the mailbox and do a little more than what it already offers by default.
Here we see the top 10 Google scripts that you can use to automate Gmail .
First of all, let's see how these scripts work .
Each script consists of several lines of code to be written in a Google Script sheet which will then be saved and authorized for your account and executed with the relative button.
For each script you must specify how often or when the script must be run on your Gmail account.
To do this, go to the Resources Menu -> current project trigger and add a new trigger based on time or a specific action.
The best and most useful Google scripts for Gmail are:
1) Delete emails automatically after an X number of days
Very often, after reading the email, it remains in the mailbox, regardless of whether it is useful or not.
Google offers a lot of space to save every message so, in theory, deleting them would not be necessary, but if you want to make an order it would not be wrong to delete old messages marked in a certain way.
The following script can check e-mail with the "Unsubscribe" label and delete them after an "x" number of days.
Then go to the Google script site, create an empty project (make sure you are connected to your Google account) and put the following lines in it:
function auto_delete_mails () {
var label = GmailApp.getUserLabelByName ("To be deleted");
if (label == null) {
GmailApp.createLabel ('To be deleted');
else {
var delayDays = 2 // Enter # days before the message is cleared
var maxDate = new Date ();
maxDate.setDate (maxDate.getDate () - delayDays);
var threads = label.getThreads ();
for (var i = 0; i <threads.length; i ++) {
if (threads [i] .getLastMessageDate () threads [i] .moveToTrash ();
You can change the number of days ( delayDays ) before emails are deleted and set a trigger to decide when to run it, if every day, at what time.
Once activated, it will create a " Unsubscribe " label in your Gmail account.
From now on all the mails to which this label is assigned will be deleted after the X number of days chosen.
A variant of this script and other details are in the post on how to set up Auto-deletion or archiving of Email in Gmail for messages older than X days.
2) Pause the reception of emails in Gmail
This script has become unnecessary since the feature is now included in Gmail.
3) Receive Gmail emails via SMS
This is one of the best Gmail scripts, among the most popular and used ones which is based on the ability of Google Calendar to send SMS
A variable of that script is the following, to be used to receive only important messages via SMS .
Create a new Google script with the following code:
function Gmail_send_sms () {
var label = GmailApp.getUserLabelByName ("Send SMS");
if (label == null) {
GmailApp.createLabel ('Send SMS');
else {
var threads = label.getThreads ();
var now = new Date (). getTime ();
for (var i = 0; i <threads.length; i ++) {
var message = threads [i] .getMessages () [0];
var from = message.getFrom ();
var subject = message.getSubject ();
CalendarApp.createEvent (subject, new Date (now + 60000), new Date (now + 60000), {location: from}). AddSmsReminder (0);
label.removeFromThreads (threads);
Save and set a trigger to run every 5 minutes.
In Gmail, set a filter to add the " Send SMS " label to messages considered important or priority automatically by Gmail and the script will send them via SMS.
4) Plan the scheduled sending of Email Gmail
In this case there is no need to create a new script, just install it already done and ready from this page of Gmail delay Send.
Once you have authorized the script to access Gmail, you are redirected to another page where you can configure the script through various menu options written in English but quite intuitive. Once configured, you can then proceed to postpone the sending of an email including date and time and save it as a draft with the label " GmailDelaySend / ToSend ".
5) Save messages arrived in Gmail as PDF in Google Drive
If you want to archive Email messages in Google Drive as a PDF file you can use the following script. The script saves all the messages of a conversation in a single PDF file in Google Drive and also saves any attachments in a folder.
Create a new Google script with the code on this page, Save and set a trigger to run at regular intervals. When you want to save a PDF message on Google Drive, just assign it as a " Save to PDF " label.
6) Mail merge in Gmail to send personalized emails to multiple contacts is a script already explained in another article, to send the same personalized messages but with some different variables to multiple contacts, therefore calling them by name and appearing to be all handwritten and not automatic .
7) Send self-destructing messages
In this case, the trick is done through this already configured worksheet that can only be read within 10 seconds of opening, after which its content is deleted. The script is explained in this post.
8) Find the biggest messages
Again there is a script that, to do it first, you can quickly apply by authorizing the FindBigMails application
9) Custom statistics on the use of Gmail
Thanks to the Gmail Meter script, already explained in another article, you can extract many statistics and customized reports on your activity in Gmail.
10) Track Gmail messages with Google Analytics for read receipt
By having a free account on Google Analytics, it is possible to track the reception and reading of messages sent via a simple script.
This script is already active in this spreadsheet to be copied to your Google Docs account and to be executed via the top Email Tracker button.
Once the script is authorized, press Email Tracker -> Send Mail, choose the draft to be tracked (the message must be already prepared), indicate the number of Analytics accounts that start with UA-xxxx and send it. When that message is opened and then read, the trace of that visit will appear in Analytics in real time.
With Google Script, there are many things that can be done on Gmail and if we also think about extensions for Gmail on Google Chrome, only imagination can limit the possibilities of this multifunctional web application.
READ ALSO: Order the inbox with filters and aliases in Gmail to manage the emails received

Leave Your Comment

Please enter your comment!
Please enter your name here