Google Cloud Champion Innovators

Google Cloud Innovators

Regardless if you use Cloud to build, modernize, train, teach, or even for fun - in our eyes you are an Innovator. The Innovators program is here to accelerate your learning and growth on Google Cloud, and to recognize you for the contributions you make to the broader Cloud community.

Champions

We recognize all these individuals for being at the top of their game technically - and for going further to inspire, invigorate, and challenge the Google Cloud community and our product teams by sharing their technical knowledge and contributing to conferences, open source projects, forums, blogs, workshops, community events, and social media.

Sending Gmail with Title and Body Including Emoji using Google Apps Script

Gists

This is a sample script for sending Gmail with the title and body including Emoji using Google Apps Script.

Sending Gmail with Title and Body Including Emoji using Google Apps Script

Sample script

This sample script uses Gmail API. So please enable Gmail API at Advanced Google services. Ref

const convert_ = ({ to, emailFrom, nameFrom, subject, textBody, htmlBody }) => {
  const boundary = "boundaryboundary";
  const mailData = [
    `MIME-Version: 1.0`,
    `To: ${to}`,
    nameFrom && emailFrom ? `From: "${nameFrom}" <${emailFrom}>` : "",
    `Subject: =?UTF-8?B?${Utilities.base64Encode(
      subject,
      Utilities.Charset.UTF_8
    )}?=`,
    `Content-Type: multipart/alternative; boundary=${boundary}`,
    ``,
    `--${boundary}`,
    `Content-Type: text/plain; charset=UTF-8`,
    ``,
    textBody,
    ``,
    `--${boundary}`,
    `Content-Type: text/html; charset=UTF-8`,
    `Content-Transfer-Encoding: base64`,
    ``,
    Utilities.base64Encode(htmlBody, Utilities.Charset.UTF_8),
    ``,
    `--${boundary}--`,
  ].join("\r\n");
  return Utilities.base64EncodeWebSafe(mailData);
};

// Please run this function.
function main() {
  const obj = {
    to: "###", // Please set the email for `to`.
    emailFrom: "###", // Please set the email for `from`.
    nameFrom: "sample name",
    subject: "Hello World 😃⭐",
    textBody: "sample text body 😃⭐",
    htmlBody: "<p>Hello World 😃⭐</p>",
  };
  Gmail.Users.Messages.send({ raw: convert_(obj) }, "me");
}
  • In order to use Emoji in the subject, the subject value is converted to the base64 data. And, it is used as =?UTF-8?B?###?=. Ref
  • About the method for including Emoji to the email body, I have answered it at this thread of Stackoverflow.

Reference

Compiling Continuous Numbers using Google Apps Script

Gists

This is a sample script for compiling the continuous numbers using Google Apps Script. For example, the values of [4, 5, 9, 3, 10, 5, 11, 7, 7, 13, 1] are converted to ["1","3-5","7","9-11","13"].

Sample script

const compilingNumbers = (ar) => {
  const { values } = [...new Set(ar.sort((a, b) => a - b))].reduce(
    (o, e, i, a) => {
      if (
        o.temp.length == 0 ||
        (o.temp.length > 0 && e == o.temp[o.temp.length - 1] + 1)
      ) {
        o.temp.push(e);
      } else {
        if (o.temp.length > 0) {
          o.values.push({ start: o.temp[0], end: o.temp[o.temp.length - 1] });
        }
        o.temp = [e];
      }
      if (i == a.length - 1) {
        o.values.push(
          o.temp.length > 1
            ? { start: o.temp[0], end: o.temp[o.temp.length - 1] }
            : { start: e, end: e }
        );
      }
      return o;
    },
    { temp: [], values: [] }
  );
  return values;
};

// Please run this function.
function main() {
  const ar = [4, 5, 9, 3, 10, 5, 11, 7, 7, 13, 1]; // This is sample values.

  const values = compilingNumbers(ar);
  console.log(values);

  const res = values.map(({ start, end }) =>
    start == end ? start.toString() : `${start}-${end}`
  );
  console.log(res);
}

When this script is run, console.log(values) and console.log(res) show [{"start":1,"end":1},{"start":3,"end":5},{"start":7,"end":7},{"start":9,"end":11},{"start":13,"end":13}] and ["1","3-5","7","9-11","13"], respectively. From this result, it is found that the continuous numbers were compiled.

Sending Outlook Emails using Microsoft Account with Google Apps Script

Gists

This is a sample script for sending Outlook emails using Microsoft account with Google Apps Script.

Sending Outlook Emails using Microsoft Account with Google Apps Script

Before you use this script, please install OnedriveApp which is Google Apps Script library. Ref And, please authorize your Microsoft account for using Microsoft Graph API. Ref

Sample script

function myFunction() {
  const obj = [
    {
      to: [{ name: "### name ###", email: "### email address ###" }, , ,],
      subject: "sample subject 1",
      body: "sample text body",
      cc: [{ name: "name1", email: "emailaddress1" }, , ,],
    },
    {
      to: [{ name: "### name ###", email: "### email address ###" }, , ,],
      subject: "sample subject 2",
      htmlBody: "<u><b>sample html body</b></u>",
      attachments: [blob],
      bcc: [{ name: "name1", email: "emailaddress1" }, , ,],
    },
  ];

  const prop = PropertiesService.getScriptProperties();
  const odapp = OnedriveApp.init(prop);
  const res = odapp.sendEmails(obj);
  console.log(res);
}

In this sample script, 2 emails are sent using Microsoft Graph API with your Microsoft account. By this, both Outlook Emails and Google Emails can be used by Google Apps Script.

Retrieving List of All Emails of Microsoft Account using Google Apps Script

Gists

This is a sample script for retrieving the list of all emails of Microsoft account and putting them to Google Spreadsheet using Google Apps Script.

Retrieving List of All Emails of Microsoft Account using Google Apps Script

I updated OnedriveApp to v1.2.0 by adding 1 method for retrieving the access token and 7 methods for managing emails of Microsoft account. By this, the emails got to be able to be gotten and sent using Microsoft account using OnedriveApp with Google Apps Script.

Directly Submitting Answers to Google Form using Google Apps Script

Gists

This is a sample script for directly submitting answers to Google Form using Google Apps Script.

The sample Google Form is as follows.

Directly Submitting Answers to Google Form using Google Apps Script

For this Google Form, this sample script submits the values of sample text, option2 and option1, option2, sample option to Google Form.

Sample script

For the multiple answers, it seems that it is required to send the values as the query parameter. I thought that the same key is used.

About Donation

From before, I have gotten several contacts about the donation to me. Thank you so much. So, today I could prepare the PayPal.Me. You can donate to me using the following URL.

https://paypal.me/tanaikech