diff --git a/.gitignore b/.gitignore index d3596a4..71dd5a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ # clasp-related files .clasp.json -appsscript.json # for testing src/test.js \ No newline at end of file diff --git a/README.md b/README.md index a0bc790..f8b7acb 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/appsscript.json b/appsscript.json new file mode 100644 index 0000000..e17e321 --- /dev/null +++ b/appsscript.json @@ -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" + ] +} diff --git a/src/mailMerge.js b/src/mailMerge.js index 9ec9776..0909042 100644 --- a/src/mailMerge.js +++ b/src/mailMerge.js @@ -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, @@ -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); @@ -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); @@ -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('');