Code Monkey home page Code Monkey logo

gmail-mail-merge's Introduction

title description labels material_icon create_time update_time
Yet another mail merge using Gmail and Google Sheets
Yet another Gmail Mail Merge, based on the script by Martin Hawksey. https://github.com/gsuitedevs/solutions/tree/master/mail-merge
Sheets, Gmail
merge_type
2020-05-22
2021-04-17

Yet another Gmail Mail Merge, based on the script by Martin Hawksey. https://github.com/gsuitedevs/solutions/tree/master/mail-merge

  • It uses a separate sheet for metadata to control the merge process, so that you can list and reference multiple merges, using the "Merge Sheet Name" variable. Just use this one sheet for all of your merges, and keep historic ones around. There are two modes of operation:
    • Send Scheduled Emails: You can have it send all merge mails that need to be sent after a certain date.
    • Run Specific Row Mail Merge: Run a specific mail merge corresponding to a row of the Metadata sheet.
  • The above is also useful for connecting with Google Form output, where responses come in a separate "Form Responses 1" sheet.
  • It also draws the template email from the user's emails using standard Gmail search queries. This allows you to use both sent-mail, mail using a particular label (e.g., label:mail-merge) or drafts (e.g., in:drafts) all as ways for finding the template to use.
  • It adds a debugging variable which should send the email only to a debugging email address, with pop-up alerts for checking the status of the merge process.
  • It enables the sending of emails with emoji in both the text and subject lines.
  • It can customize the subject line, feeding the subject line through the mail merge variable replacement process.
  • Local (per email) merge sheet overrides of values from the metadata sheet, for "CC" (appends), "Reply To" and "Sender Name" columns.

Try it

Create a copy of the sample Gmail Mail Merge++ spreadsheet.

Update the Recipient Email Address in the column with email addresses you would like to use in the mail merge in the Mail Merge sheet.

Create a message in your Gmail account using markers like {{First name}}, which correspond to column names, to indicate text you’d like to be replaced with data from the copied spreadsheet.

In the Metadata worksheet, specify the template email (commonly in Drafts, specified by in:draft using the Search Restriction and the Search Subject Line) that you want to use a source for the mass mailing.

In the copied spreadsheet, click on custom menu item Mail Merge > Run Specific Row Mail Merge. For example, to run the example mail merge partially completed, type 2.

A dialog box will appear and tell you that the script requires authorization. Read the authorization notice and continue.

The Email Sent column will update with the message status, in both the Metadata and Mail Merge sheets.

Next steps

Additional columns can be added to the spreadsheet with other data you would like to use. Using the {{}} annotation and including your column name as part of your Gmail draft will allow you to include other data from your spreadsheet. If you change the name of the Recipient or Email Sent columns this will need to be updated by opening Tools > Script Editor.

The source code includes a number of additional parameters, currently commented out, which can be used to control the name of the account email is sent from, reply to email addresses, as well as bcc and cc'd email addresses.

Enabling Scheduled Sending

The script also has the function to send scheduled emails, so that you can plan your mass customized mailings in advance. You need to specific a date/time correctly in the Schedule Send column in the Metadata worksheet. When the sendScheduledEmails function is run, any row's email whose time is in the past and whose Status column is not blank is run. By default any row that has this column blank is ignored by the Scheduled Send facility. This facility is similar to the "crontab" means in Un*x. You can also trigger this function directly on the Mail Merge > Send Scheduled Email dropdown.

There are two steps to get this functionality to run. Let's look at these.

  1. You must install an Installable Trigger to the script and specify the sendScheduledEmails as the target. To do this, select Tools > Script Editor to get to the Script Editor. In the Script Editor, select Edit > Current Project's Triggers. Press the blue Add Trigger button in the lower right to add a trigger. You can set the trigger as you like; for example to check on an hourly basis, follow the set of images below.

Step 1. Step 2. Step 3.

  1. You must change the SpreadsheetID variable on Line . This is because when the function is run by the trigger it needs to know which worksheet to reference. The SpreadsheetID is displayed in the URL of the spreadsheet in your browser. The ID should look something like the information in bold. https://docs.google.com/a/yourdomain.com/spreadsheets/d/**11dS1-kunj-sHA49WVtyACIqmCYOGn3Y5N1lIPPIQZoU**/edit?usp=sharing

With these two steps completed, the Send Scheduled Email function will run at the interval you have specified.

Known Bugs

  • BCC doesn't seem to work currently.
  • {{token}} replacements may have issues if they contain HTML tags. This does work but may have issues. We suggest piloting your merge first to check for problems before sending out an actual bulk mail.

Development Plans

  • Add BCC.
  • Debug the prompt box for cancel button.
  • Needs better installation instructions.

gmail-mail-merge's People

Contributors

knmnyn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gmail-mail-merge's Issues

Schedule Send Crontab

Should be accomplished with the Script triggers facility.

  • Should contain a method to check whether triggers are on
  • and another method that can turn them on or off.

Inconsistent formatting of {{token}} blocks in draft emails will cause token replacement to fail for HTML

I am not certain I got the root cause of this issue right, but I noticed that the HTML version of the email being sent out inn my test merge had a blank where the name should have been swapped in. Inspecting the html showed that there were tags in the middle of the token - possibly in between some of the parentheses? So naive replacement might have resulted in the replacedment html being interpreted as a malformed tag or something.

Removing formatting from the {{token}} text in my draft fixed it.

It might be worth documenting that this can be an issue.

Leaving cc field blank in metadata sheet but populating in merge sheet causes invalid email error

If I do not populate the (per-merge) CC field in the Metadata sheet, but do use (per-email) CC in my merge sheet, then I will end up with a CC value something like undefined, <[email protected]> and when I call MailApp.sendEmail it will throw an invalid email error.

The problem appears to be on line 211:
const cachedCC = msgOptionsHash['cc']; - this is undefined in the case that CC in the metadata sheet wasn't populated. msgOptionsHas will only have a cc attribute at all if it is set, on line 154:if (cc != "") { msgOptionsHash['cc'] = cc; }, if the CC field is populated in the metadata sheet.

So when that undefined cc value gets cached at 211 it gets cached as undefined, and restored as such at 238, then the per-email cc gets appended to that undefined.

General workflow clarification, small redundancies.

Hello Dr Min,

I've been going through Code.gs to better understand how to enhance the mail merge for our purposes. I am, however, a little unclear with what our desired workflow will be.

My understanding of the mail merge's use is to allow us to send student-specific emails that fall under a set number of templates. For this purpose, I would think that we need to build the following:

  1. A way to port students' "progress" into Google Sheets. By "progress" I mean whatever metric required to assign each student to a relevant email template for the current week/period.
  2. A mail merge script that, given these groups, sends per-student customized emails to them at the right time (cron) that, perhaps, bcc'es their tutors if required.

Is my understanding of the workflow correct? If so, I intend to streamline the code to better serve this purpose. Generally, there are some small redundancies in the code and between the sheets (e.g. duplicate cc columns) that I am also working to remove.

Typo in script in sample sheet breaks merge

The sample Gmail Mail Merge++ spreadsheet linked to from readme.md contains a version of this script with a typo that causes merge to fail with the error ReferenceError: msgOptionHash is not defined at Code:242:11 at Array.forEach (<anonymous>) at sendEmails_ (Code:222:9) at Code:162:27 at Array.forEach (<anonymous>) at sendEma….

The typo is on line 238: msgOptionHash['cc'] = cachedCC; note the missing s - it should be msgOptionsHash

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.