@docsoc/mailmerge-cli v1.6.0
mailmerge-cli
This is a CLI tool that can be used to generate emails from templates, regenerate them after modifying the results, upload them to Outlook drafts and send them.
It was created using oclif and nx.
Since it was created using oclif, when developing on it please use oclif's commands to e.g. add new commands.
The CLI tool also acts as a library for user-facing function that might help when using @docsoc/mailmerge - see src/mailmerge for more info.
Installation
Production
npm install -g @docsoc/mailmerge-cliLocally
- Run
npm installfrom the root of the repo - Run
npm run buildin this folder (email/mailmerge-cli) - Run
npm linkin this folder - this addsdocsoc-mailmergeto your path
Quick Start
In a blank directory, run docsoc-mailmerge init, then read the output and follow the steps.
Detailed Steps
- In a blank directory somewhere (known as the "mailmerge workspace"), create these folders & files:
./data/names.csv- CSV file with at the minimumto&subjectcolumns./templates/template.md.njk- nunjucks markdown template for your emails (see/email/workspace/templates/tempkate.md.njkfor an example, where/is the repo root)./templates/wrapper.html.njk, a HTML wrapper for the email (use the contents of/email/workspace/templates/wrapper.html.njk)
- Run
docsoc-mailmerge generate nunjucks --helpand read the help text - Run
docsoc-mailmerge generate nunjucks ./data/names.csv -o ./output --htmlTemplate=./templates/wrapper.html.njk. You'll be asked for a runname: generated emails will be placed at./output/<runname>- Each record in the CSV will result in 3 files in
./output/<runname>: an editable markdown file to allow you to modify the email, a HTML rendering of the markdown that you should not edit, and a.jsonmetadata file - The HTML files, which is what is actually sent, can be regenerated after edting the markdown files with
regeneratecommand (see below) - If you want to edit the to address or subject after this point you will need to edit the JSON files; csv edits are ignored. If you edit the CSV, delete all outputs and run generate again.
- Each record in the CSV will result in 3 files in
- Edit the generated markdown files - this allows you to edit the emails
- Run
docsoc-mailmerge regenerate ./output/<runname>- this will re-render the markdown files into the HTML previews. These HTML previews are then what is sent to receipients. You can callregenerateas many times as you want. - Once you've edited & checked all the email markdowns as needed & checked and regenerated if needed the HTMLs, run this command to send the emails:
docsoc-mailmerge send ./output/<runname>.- NOTE: Send does not run
regenerate, so if you edited any markdown files ensure you ranregeneratebefore runningsend
- NOTE: Send does not run
- Done! Sent email previews will be moved to
./output/<runname>/sentto prevent double sending if the send is stopped halfway through.
Attachments
I recommend placing attachments in an attachments folder.
2 ways to add attachments:
- If you want a different attachments per email, create a column called
attachmentin the CSV with the path to the attachment relative to the workspace root - e.g. if you CSV is in./data/names.csvand the attachment in./attachment/image.jpg, the CSV row should have./attachments/image.jpgas it's value in theattachmentcolumn- Use multiple columns e.g.
attachment1,attachment2for multiple attachments - When you run
generateyou will be asked which columns to use for attachments - To edit which attachment to use ater
generate, edit the JSON metadata files.
- Use multiple columns e.g.
- If you want the same attachment to all emails, use the
-aflag of generate, e.g.docsoc-mailmerge generate nunjucks ./data/names.csv -o ./output -a ./attachments/image.jpg -a ./attachments/image2.jpg.- Note that if you pass the CLI option, any info about attachments in the CSV is ignored.
BCC, CC & Multi to
- For multi-to: Separate the list of emails with a space in the CSV column
- For CC: Add a column called
ccwith space separated emails in, and make sure to pass--ccto thegeneratecommand - For BCC: Add a column called
bccwith space separated emails in, and make sure to pass--bccto thegeneratecommand
This library was generated with Nx.
Uploading to drafts
You can also upload the emails to drafts instead of sending them. To do this, run docsoc-mailmerge upload-drafts ./output/<runname>. This will upload the emails to drafts instead of sending them.
Hitting Rate Limits?
Use the -s flag to set a delay between each email sent. The delay is in seconds.
Building
Run nx build mailmerge-cli to build the library.
Running unit tests
Run nx test mailmerge-cli to execute the unit tests via Jest.