In order to send automated emails to people and also where there is a need of reading data from google sheets, you can use Apps script which is a built-in extension in google sheets. You can send your emails in your favorite
HTML templates and use
gs to use variables inside your
To do this, follow this instruction.
- First, go to google sheets and choose
- Copy and Paste the
script.gsfile from this repository to
Code.gsin Apps script.
I have explaned some parts of the code.
const headers = ws.getRange('A2:H49').getDisplayValues()//get table headers name;
getRange function gets the range of your cells name. For instance, if you want to read data from the cells selected in the image, you should enter
C2:G16 as the parameters in this function.
- Add your HTML file using the ➕ button at the left side of the page beside the
Copy and paste the
Template.htmlcode inside this repository to a new
HTMLfile you’ve created.
Whenever you want to use your google sheet data in yout
HTMLfile, use the tag below.
<?= variable_name ?>
For instance, I want to read HW1 from google sheets. I have assigned
ex1variable uing this:
const ex1 = headers[data];
Working with cells is exactly same as working with 2d arrays.
And then, I use this tag in order to use the value of
ex1 in my html file.
<li>تمرین اول: <?= ex1 ?></li>
- After all these, click on the
Runbutton to run this script.
- There is an example in the
srcdirectory in which you can see the templates of
- If you want to send automated emails, you should first allow google sheets to access your emails and your google drive.