Did you know that you can navigate the posts by swiping left and right?
This post contains a guide on how to automate the contents of your Gmail signature (Random Daily Quotes in this case)
There are other options in the market such as API ninjas, zen quotes API and so on but we will use quotable.io here.
The quotable.io provides an API endpoint which we can use to get a random quote each time we send a GET request.
Showing off my cool terminal ASCII art :p. Visit here for cool ASCII art.
Visit here to convert your texts to ascii art
You can see if we do curl https://api.quotable.io/random
, we get JSON
key-value pairs. We can also use curl https://api.quotable.io/random\?tags=technology,famous-quotes
for quotes that belong to specific types. See the documentation from Quotable for more options.
Going straight into the project, the first step you need to perform is to go this the Google App Scripts and log in with your Gmail account.
You should see a window similar to this.
Click on the
New Project
button.
You should see something like this:
Delete function myFunction(){} and add this code to the console:
function dailyQuoteUpdate() {
var response = UrlFetchApp.fetch("https://api.quotable.io/random");
var quoteData = JSON.parse(response.getContentText());
var signature = `Best,<br>John Doe<br><br><i><u>Quote of the day</i></u>: <i>"${quoteData.content}" — ${quoteData.author} </i>`;
var resource = {
signature: signature
};
console.log(quoteData)
var userEmail = Session.getActiveUser().getEmail();
Gmail.Users.Settings.SendAs.patch(resource, userEmail, userEmail);
}
Send an HTTP GET request to the quotable.io
API’s /random
endpoint which returns a random quote. The JSON.parse()
will give us a javascript object quoteData
to get the values we want using quoteData.key
. We want quoteData.content
and quoteData.author
as seen in the above demo of quotable.io.
Create a signature
object which will contain the defined signature. We use the values from quoteData
here as mentioned above.
We can log the API response data using console.log(quoteData)
We need to identify whose signature needs to be updated. We can get the current session user’s email using Session.getActiveUser().getEmail();
.
Gmail.Users.Settings.SendAs.patch
allows us to change just certain parts of the settings: the signature in this case. We have defined resources as:
var resource = {
signature: signature
};
So, the signature will be updated to the custom signature we just created.
The images speak for themselves:
Save your URL
You might face this error while running the script: (Press on
Execution log
if you cannot see the error)
You will be asked to Review Permission
You will be asked to Allow Permission for the Script
Your new email signature should be there now.
Signature
section:Your signature is changed now!!
Triggers
Time-driven
for event sourceDay timer
for trigger typeCongratulations! You now have a daily motivation for yourself and your connections!