<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: IMTheNachoMan</title>
    <description>The latest articles on Forem by IMTheNachoMan (@imthenachoman).</description>
    <link>https://forem.com/imthenachoman</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F292477%2Ff6d00f2b-a825-49c0-8305-d68564ebc042.jpeg</url>
      <title>Forem: IMTheNachoMan</title>
      <link>https://forem.com/imthenachoman</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/imthenachoman"/>
    <language>en</language>
    <item>
      <title>Templated Emails With Google Apps Script To Make Your Brand Team Happy</title>
      <dc:creator>IMTheNachoMan</dc:creator>
      <pubDate>Thu, 08 Oct 2020 02:30:54 +0000</pubDate>
      <link>https://forem.com/imthenachoman/templatize-your-google-apps-script-e-mails-and-make-your-brand-team-happy-4ee0</link>
      <guid>https://forem.com/imthenachoman/templatize-your-google-apps-script-e-mails-and-make-your-brand-team-happy-4ee0</guid>
      <description>&lt;h1&gt;
  
  
  Table of Contents
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;About&lt;/li&gt;
&lt;li&gt;Pre-Requisites&lt;/li&gt;
&lt;li&gt;How It Works&lt;/li&gt;
&lt;li&gt;
Let's Do It

&lt;ul&gt;
&lt;li&gt;Step 1: The Core HTML File&lt;/li&gt;
&lt;li&gt;Step 2: The Email Specific HTML Files - One For Each Email I Want To Send&lt;/li&gt;
&lt;li&gt;Step 3: Putting It All Together&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;The End&lt;/li&gt;

&lt;/ul&gt;

&lt;h1&gt;
  
  
  About
&lt;/h1&gt;

&lt;p&gt;While we may not think about branding -- font, format, layout, structure, etc. -- in our personal emails, &lt;strong&gt;if you work in an organization then you probably can't get away from their branding requirements, even for emails&lt;/strong&gt;. And rightfully so -- staying on brand with your communication is crucial for your customers/clients, &lt;strong&gt;including emails&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If your organization is using &lt;a href="https://workspace.google.com/" rel="noopener noreferrer"&gt;G-Suite&lt;/a&gt; (now known as &lt;a href="https://workspace.google.com/" rel="noopener noreferrer"&gt;Google Workspaces&lt;/a&gt;) then you're hopefully using &lt;a href="https://developers.google.com/apps-script/" rel="noopener noreferrer"&gt;Google Apps Script&lt;/a&gt; to automate your email communication. &lt;em&gt;(If you aren't, why not? It's a brilliant way to manage your communications.)&lt;/em&gt; You probably have different types of emails -- for different purposes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do all of your emails have the same look-and-feel? Do they all match your organization's branding requirements? How easy is it to update the format for all of them if you need to change a core/base element? Maybe the company tagline and color theme changed -- how quickly can you get all of your emails updated?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I am going to show you how to create templated emails so that all of the emails you send have the same look-and-feel and are easy to maintain/update.&lt;/p&gt;

&lt;h1&gt;
  
  
  Pre-Requisites
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Doing this does require working with HTML -- the HTML that will be used for the email. HTML is out-of-scope for this article. If you need help with writing HTML for your emails, there are many online sites that let you compose your emails in &lt;a href="https://en.wikipedia.org/wiki/WYSIWYG" rel="noopener noreferrer"&gt;WYSIWYG&lt;/a&gt; and spit out the associated HTML.

&lt;ul&gt;
&lt;li&gt;In a future article I will explain how to do this using a &lt;a href="https://www.google.com/docs/about/" rel="noopener noreferrer"&gt;Google DocS&lt;/a&gt; for the email template, instead of having to mess with HTML.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;You should also understand how Google Apps Script's &lt;code&gt;HtmlService&lt;/code&gt; works, especially &lt;code&gt;HtmlTemplate&lt;/code&gt;. See &lt;a href="https://developers.google.com/apps-script/reference/html/html-service" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="https://developers.google.com/apps-script/reference/html/html-service" rel="noopener noreferrer"&gt;https://developers.google.com/apps-script/reference/html/html-service&lt;/a&gt; for more information.&lt;/li&gt;

&lt;/ul&gt;

&lt;h1&gt;
  
  
  How It Works
&lt;/h1&gt;

&lt;p&gt;The basic idea is very simple. You have:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A "base" HTML file that lays out the base of your email -- the overall look-and-feel&lt;/li&gt;
&lt;li&gt;X # of email specific HTML files that include the actual specific content for that email without having to worry about style/formatting/look-and-feel&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For example, you may have the following types of emails you send and you want all of them to have the same look-and-feel:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Welcome email&lt;/li&gt;
&lt;li&gt;Support request auto-reply&lt;/li&gt;
&lt;li&gt;Bill/Invoice&lt;/li&gt;
&lt;li&gt;Newsletter&lt;/li&gt;
&lt;li&gt;etc...&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you need to send an email, you just need to specify the email specific HTML file (#2) and the code will put it together with the base HTML file (#1).&lt;/p&gt;

&lt;h1&gt;
  
  
  Let's Do It
&lt;/h1&gt;

&lt;p&gt;You can view my code at &lt;a href="https://script.google.com/d/1KirtuDBLCzWMNIBYEb1MNI_tQ93f3UCyS7iuBinAf3LNtXukqvrn-F7S/edit?usp=sharing" rel="noopener noreferrer"&gt;https://script.google.com/d/1KirtuDBLCzWMNIBYEb1MNI_tQ93f3UCyS7iuBinAf3LNtXukqvrn-F7S/edit?usp=sharing&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: The Core HTML File
&lt;/h2&gt;

&lt;p&gt;The first thing you need to do is create the base HTML file with the HTML elements that you want all of your emails to have. Example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;base.html&lt;/code&gt;&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="na"&gt;target=&lt;/span&gt;&lt;span class="s"&gt;"_top"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;body&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"font-family: Consolas; font-size: 12px; color: blue"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&amp;lt;h1&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?= header ?&amp;gt;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&amp;lt;hr&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
            &lt;span class="cp"&gt;&amp;lt;?!= content ?&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&amp;lt;hr&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
            Thank you!&lt;span class="nt"&gt;&amp;lt;br&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
            _Nacho
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My example has:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CSS formatting styles&lt;/li&gt;
&lt;li&gt;a heading area that all of my emails will hvae&lt;/li&gt;
&lt;li&gt;a content area where the actual specific email content will go&lt;/li&gt;
&lt;li&gt;a signature area that all of my emails will have&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Notes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the &lt;code&gt;base.html&lt;/code&gt; file, &lt;code&gt;heading&lt;/code&gt; and &lt;code&gt;content&lt;/code&gt; will be passed down as &lt;a href="https://developers.google.com/apps-script/guides/html/templates#pushing_variables_to_templates" rel="noopener noreferrer"&gt;template variables&lt;/a&gt;. More on this &lt;a href="https://dev.tostep-3-putting-it-all-together"&gt;below&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;For &lt;code&gt;content&lt;/code&gt; we use &lt;a href="https://developers.google.com/apps-script/guides/html/templates#force-printing_scriptlets" rel="noopener noreferrer"&gt;force-printing scriplets&lt;/a&gt; because we're passing it evaulated HTML (from the email specific HTML file). &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: The Email Specific HTML Files - One For Each Email I Want To Send
&lt;/h2&gt;

&lt;p&gt;Now you need X # of specific email HTML files. Examples:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;email1.html&lt;/code&gt;&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;This is email 1.&lt;span class="nt"&gt;&amp;lt;br&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;br&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
Today's date is: &lt;span class="cp"&gt;&amp;lt;?= data.todayDate ?&amp;gt;&lt;/span&gt;.&lt;span class="nt"&gt;&amp;lt;br&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;email2.html&lt;/code&gt;&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;This is email 1.&lt;span class="nt"&gt;&amp;lt;br&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;br&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
Today's date is: &lt;span class="cp"&gt;&amp;lt;?= data.todayDate ?&amp;gt;&lt;/span&gt;.&lt;span class="nt"&gt;&amp;lt;br&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;These files only include the content specific to those emails. They don't need to include all the other HTML elements that &lt;code&gt;base.html&lt;/code&gt; takes care of because, in the next part, we'll put them together.&lt;/li&gt;
&lt;li&gt;Notice that each email specific HTML file can reference its own relevant &lt;a href="https://developers.google.com/apps-script/guides/html/templates#pushing_variables_to_templates" rel="noopener noreferrer"&gt;template variables&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;All of the email specific HTML files will reference their relevant template variables through the &lt;code&gt;data&lt;/code&gt; variable. This is because when we combine the templates to put the email together we don't know what template variables we need. So, instead, we'll pass all the specific email template variables under &lt;code&gt;data&lt;/code&gt;. This will make more sense below.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 3: Putting It All Together
&lt;/h2&gt;

&lt;p&gt;Now the only thing left is to put it all together. We're going to use a helper function that we can call when we want to send an email. The helper function will put the email together and send it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 * send a templated email
 * 
 * @param {Object} data - configuration options
 * @param {string} data.to - recipient's email address
 * @param {string} data.subject - the email subject
 * @param {string} data.header - the header of the email body
 * @param {string} data.emailTemplate - the name of the email file we want to send
 * @param {string} data.emailData - any data we want to pass down to the email body
 */&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;_sendTemplatedEmail_&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// first, lets get the generated content of the specific email we want to send&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;specificEmail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;HtmlService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createTemplateFromFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;emailTemplate&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// we need to send the data relevnat to this specific email&lt;/span&gt;
    &lt;span class="nx"&gt;specificEmail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;emailData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// next we need to get the base.html file and put it all together&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;baseEmail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;HtmlService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createTemplateFromFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;base&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// send the header (used in base.html)&lt;/span&gt;
    &lt;span class="nx"&gt;baseEmail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;header&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;header&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// send the content for this specific email&lt;/span&gt;
    &lt;span class="c1"&gt;// we need to evaulate it and get the HTML content&lt;/span&gt;
    &lt;span class="nx"&gt;baseEmail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;specificEmail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;getContent&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// now we can send the email&lt;/span&gt;
    &lt;span class="nx"&gt;GmailApp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sendEmail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// for the emial we need the evaulated HTML content&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;htmlBody&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;baseEmail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;getContent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that is it. We can test it out like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;testIt&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// lets send email1&lt;/span&gt;
    &lt;span class="nf"&gt;_sendTemplatedEmail_&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;to&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getActiveUser&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;getEmail&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;

        &lt;span class="c1"&gt;// the subject we want for this email&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;subject&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;testing - email 1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

        &lt;span class="c1"&gt;// the header we want for this email&lt;/span&gt;
        &lt;span class="c1"&gt;// this will go in the header area of base.html&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;header&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;this is a test of email 1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

        &lt;span class="c1"&gt;// the email specific HTML file: email1.html&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;emailTemplate&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;email1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

        &lt;span class="c1"&gt;// the data relevant to email1.htlm&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;emailData&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;todayDate&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Utilities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;formatDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nx"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getScriptTimeZone&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;yyyy-mm-dd&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="c1"&gt;// lets send email2&lt;/span&gt;
    &lt;span class="nf"&gt;_sendTemplatedEmail_&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;to&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getActiveUser&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;getEmail&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;subject&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;testing - email 2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;header&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;this is a test of email 2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;emailTemplate&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;email2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

        &lt;span class="c1"&gt;// notice we are sending different data&lt;/span&gt;
        &lt;span class="c1"&gt;// because email2.html expects different template variables&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;emailData&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;randomNumber&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which sends two emails, each using the same &lt;code&gt;base.html&lt;/code&gt;, but with their own specific content:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;testing - email 1&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FcAbkbtd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FcAbkbtd.png" alt="testing - email 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;testing - email 2&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FP6appje.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FP6appje.png" alt="testing - email 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  The End
&lt;/h1&gt;

&lt;p&gt;Now you can have as many email specific HTML files you need and all of them will use the same &lt;code&gt;base.html&lt;/code&gt; so they will all have the same look-and-feel. When you need to change something, the style, the signature, anything, you just have to update &lt;code&gt;base.html&lt;/code&gt; and you're done.&lt;/p&gt;

&lt;p&gt;I hope you found this article helpful. Please leave a comment with any questions, concerns, feedback, or anything. Would love to hear what you think!&lt;/p&gt;

</description>
      <category>gas</category>
      <category>googleappsscript</category>
      <category>tutorial</category>
      <category>branding</category>
    </item>
  </channel>
</rss>
