|
| 1 | +To get started: |
| 2 | + |
| 3 | +1. Put your own CSV in the `data` folder, with at the minimum `to` and `subject` columns. |
| 4 | + 1. You can also add `cc` and `bcc` columns (to use them you will need to pass the correct CLI option though) |
| 5 | + 2. `to`, `cc`, and `bcc` can be a space-separated list of emails. |
| 6 | + 3. You can add any other columns you like, and they will be available in the template. |
| 7 | + 4. For attachments, add a column with the name `attachment` with a singular path to the file to attach relative to th workspace root (e.g. `./attachments/image1.jpg`). |
| 8 | + 1. Or, pass the same attachment to every email using the `-a` flag to `generate` |
| 9 | + 5. For multiple attachments, have separate columns e.g. `attachment1`, `attachment2`, etc. |
| 10 | + 6. See `data/example.csv` for an example. |
| 11 | +2. Put your own nunjucks markdown email template in the `templates` folder. |
| 12 | + 1. You can also edit the default `wrapper.html.njk` file - this is what the markdown HTML will be wrapped in when sending it. It muat _always_ include a `{{ content }}` tag, which will be replaced with the markdown HTML. |
| 13 | +3. Fill in the `.env` file with your email credentials. |
| 14 | + |
| 15 | +Then run the following commands: |
| 16 | + |
| 17 | +```bash |
| 18 | +docsoc-mailmerge generate nunjucks ./data/my-data.csv ./templates/my-template.md.njk -o ./output --htmlTemplate ./templates/wrapper.html.njk |
| 19 | +# make some edits to the outputs and regenerate them: |
| 20 | +docsoc-mailmerge regenerate ./output/<runname> |
| 21 | +# review them, then send: |
| 22 | +docsoc-mailmerge send ./output/<runname> |
| 23 | +``` |
| 24 | + |
| 25 | +The CLI tool has many options - use `--help` to see them all: |
| 26 | + |
| 27 | +```bash |
| 28 | +docsoc-mailmerge generate nunjucks --help |
| 29 | +docsoc-mailmerge regenerate --help |
| 30 | +docsoc-mailmerge send --help |
| 31 | +``` |
| 32 | + |
| 33 | +## What happen when you generate |
| 34 | + |
| 35 | +1. 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 `.json` metadata file |
| 36 | +2. The HTML files, which is what is actually sent, can be regenerated after edting the markdown files with `regenerate` command (see below) |
| 37 | +3. 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. |
| 38 | + |
| 39 | +## If the .env file is missing |
| 40 | + |
| 41 | +Use this template: |
| 42 | + |
| 43 | +```bash |
| 44 | +# Fill these in to send emails |
| 45 | +DOCSOC_SMTP_SERVER=smtp-mail.outlook.com |
| 46 | +DOCSOC_SMTP_PORT=587 |
| 47 | +DOCSOC_OUTLOOK_USERNAME= |
| 48 | +# Password to docsoc email |
| 49 | +DOCSOC_OUTLOOK_PASSWORD= |
| 50 | + |
| 51 | +# Optional: Fill these in to uplod drafts |
| 52 | +# You will need to create an app registration in Entra ID, restricted to the organisation, |
| 53 | +# And grant it the following permissions: |
| 54 | +# - Mail.ReadWrite |
| 55 | +# - User.Read |
| 56 | +MS_ENTRA_CLIENT_ID= |
| 57 | +MS_ENTRA_CLIENT_SECRET= |
| 58 | +MS_ENTRA_TENANT_ID= |
| 59 | +``` |
0 commit comments