Create cronjob to send mail, send message to chatwork with just a few lines of script code on Google Apps Script

Tram Ho

Hello everyone, this article I would like to share about how to create a simple cronjob on google apps script. If you are in need of creating a cronjob every day to send debt collection mail, or daily send a message to the chatwork to remind you to write reports but you do not have a server or a server, this article will help you to solve that problem … ah Google script also does a lot of interesting things in this section, I just introduce that, you guys learn more.

Introducing Google Apps Script

Google App Script is a JavaScript-based programming language that allows you to create, modify and deploy projects on Apps Script editor, Apps Script code that runs on Google servers. You can program to manipulate and interfere with many Google services such as google sheet, clendar, maps, form, drive … generally most of google services.
There are a few examples you can do with google apps script

  • With goole form: it is possible to write code so that when someone submits the form, it will send data to your api server.
  • Google sheet: write and read data from google sheet, get data from google sheet to send mail
  • Google calendar: reads the schedule data from your file to create an event on google calender

    I can do a lot of other things, but now I will guide you to create a cronjob to send mail and send messages to chartwork.

Cronjob sent mail

1. To use google script, you need a google account (this must have everyone)
2. Go to script.google.com to open a code editor
3. Select + dự án mới to write code

4. To send mail, you use the following code


After reading through, you will also understand this code, this code will use the email that you log into the app to send mail to mailTo
5. Click the button ▶ ️ for a test run

You need to give permission for this script

Select review rights

Select Advanced

Choose to go to project … (unsafe)

And click on allow to grant permissions to the email.
So finished sending test mail, 1 mail has been sent to the recipient.
6. Create triggers to run cronjob

In the edit section select the current project animation

Select Add Trigger in the lower right corner of the screen.

Modal setting appears and you install the parameters, as above, I set the script code to run around midnight to 1am.
So created the cronjob to send mail, ezz, right

Cronjob message to chatwork

I need to create cronjob and send message to chatword at 5:00 pm to remind me to write report at the end of the day. This is quite simple to do as the above email conjob and replace with the following code

We need your_bot_chatwork_token to be the token of the bot that you use to send you message to the chatwork using the bot’s account to get the token here.
With room_id, you go to the chat box where you want to send the message to get on the url, it is a string of numbers after the id.


Fix the code and then do the same as send mail. Thanks mn for watching.

Share the news now

Source : Viblo