Skip to content

Commit

Permalink
Merge branch 'develop' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ttsukagoshi committed Oct 20, 2020
2 parents 73abe99 + 0f884d6 commit ad10f55
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# clasp-related files
.clasp.json
appsscript.json

# for testing
src/test.js
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Mail Merge for Gmail
# Mail Merge for Gmail [![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/ttsukagoshi/mail-merge-for-gmail.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/ttsukagoshi/mail-merge-for-gmail/context:javascript)
Send personalized emails based on Gmail template to multiple recipients using Gmail, Google Spreadsheet, and Google Apps Script. An alternative for using BCC.

## Overview
Expand Down
11 changes: 11 additions & 0 deletions appsscript.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"timeZone": "Asia/Tokyo",
"dependencies": {},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"oauthScopes": [
"https://mail.google.com/",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/userinfo.email"
]
}
8 changes: 4 additions & 4 deletions src/mailMerge.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function sendPersonalizedEmails_(draftMode = true, config = CONFIG) {
let nmFieldCounter = 0;
for (let k in template) {
let nmField = template[k].match(config.GROUP_FIELD_MARKER);
let nmFieldCount = (nmField === null ? 0 : nmField.length)
let nmFieldCount = (nmField === null ? 0 : nmField.length);
nmFieldCounter += nmFieldCount;
}
// If group merge field marker is detected in the template when ENABLE_GROUP_MERGE is set to false,
Expand Down Expand Up @@ -149,7 +149,7 @@ function sendPersonalizedEmails_(draftMode = true, config = CONFIG) {
let groupedMergeData = groupArray_(mergeDataEolReplaced);
// Create draft or send email for each recipient
for (let i = 0; i < groupedMergeData.data.length; ++i) {
let object = groupedMergeData.data[i]
let object = groupedMergeData.data[i];
let mergeDataObjArr = [];
mergeDataObjArr.push(object);
let messageData = fillInTemplate_(template, mergeDataObjArr, config.REPLACE_VALUE, config.MERGE_FIELD_MARKER, config.ENABLE_GROUP_MERGE);
Expand All @@ -166,7 +166,7 @@ function sendPersonalizedEmails_(draftMode = true, config = CONFIG) {
let completeMessage = (draftMode === true
? 'Complete: All draft(s) created.'
: 'Complete: All mail(s) sent.');
ui.alert(completeMessage)
ui.alert(completeMessage);
} catch (e) {
let message = errorMessage_(e);
ui.alert(message);
Expand Down Expand Up @@ -328,7 +328,7 @@ function fillInTemplate_(template, data, replaceValue = 'NA', mergeFieldMarker =
let fieldMarkerText = fieldVarsCopy.map(value => value.substring(2, value.length - 2)); // assuming that the text length for opening and closing markers are 2 and 2, respectively
fieldVarsCopy.forEach(
(variable, ind) => fieldRowIndexed = fieldRowIndexed.replace(variable, datum[fieldMarkerText[ind]] || replaceValue)
)
);
fieldMerged.push(fieldRowIndexed);
}
let fieldMergedText = fieldMerged.join('');
Expand Down

0 comments on commit ad10f55

Please sign in to comment.