forked from ActiveCampaign/postmark-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into task/cleanup
# Conflicts: # readme.md # test/integration/email.test.ts # test/integration/general.test.ts # test/integration/servers.test.ts # test/integration/templates.pull.test.ts # test/integration/templates.push.test.ts
- Loading branch information
Showing
13 changed files
with
307 additions
and
344 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
sudo: false | ||
language: node_js | ||
before_install: | ||
- npm install -g typescript | ||
branches: | ||
except: | ||
- gh-pages | ||
node_js: | ||
- 'lts/*' | ||
- '11' | ||
- '10' | ||
- '9' | ||
- '8' | ||
- '7' | ||
- node |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
<h1 align="center"> | ||
<img src="./media/[email protected]" width="100%" style="max-width:1230px;" alt="Postmark CLI"> | ||
</h1> | ||
<p align="center">A CLI tool for managing templates, sending emails, and fetching servers on <a href="https://postmarkapp.com">Postmark</a>. Nifty for integrating with a CI/CD pipeline.</p> | ||
<p align="center">A CLI tool for managing templates, sending emails, and fetching servers on <a href="https://postmarkapp.com">Postmark</a>. <br/>Nifty for integrating with a CI/CD pipeline.</p> | ||
|
||
<p align="center"> | ||
<a href="https://circleci.com/gh/wildbit/postmark-cli"><img src="https://circleci.com/gh/wildbit/postmark-cli.svg?style=svg" alt="CircleCI"></a> | ||
<a href="https://travis-ci.org/wildbit/postmark-cli"><img src="https://travis-ci.org/wildbit/postmark-cli.svg?branch=master" alt="TravisCI"></a> | ||
<a href="http://www.opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-brightgreen.svg" alt="License: MIT"></a> | ||
<a href="https://badge.fury.io/js/postmark-cli"><img src="https://badge.fury.io/js/postmark-cli.svg" alt="npm version"></a> | ||
</p> | ||
|
||
# Install | ||
## Usage | ||
|
||
- Install [Node.js](https://nodejs.org/en/) | ||
- `$ npm i postmark-cli -g` | ||
- `$ postmark` 🌈 | ||
Please see the [wiki](https://github.com/wildbit/postmark-cli/wiki) for detailed instructions about how to use the library. | ||
For quick start after installing the library, you can type `postmark` in your command line, which should show you the CLI tool available options. | ||
|
||
# Usage | ||
Check out wiki for instructions how to [send email](https://github.com/wildbit/postmark-cli/wiki/email-command), | ||
[manage templates](https://github.com/wildbit/postmark-cli/wiki/templates-command) or [list servers](https://github.com/wildbit/postmark-cli/wiki/servers-command). | ||
|
||
```bash | ||
$ postmark | ||
|
@@ -30,128 +30,17 @@ $ postmark | |
--help Show help | ||
``` | ||
|
||
## Authentication | ||
|
||
Each command requires an [account or server token](https://postmarkapp.com/support/article/1008-what-are-the-account-and-server-api-tokens) depending on the level of access required. Tokens can be passed in as environment variables: `POSTMARK_SERVER_TOKEN` and `POSTMARK_ACCOUNT_TOKEN`. | ||
|
||
```bash | ||
$ POSTMARK_SERVER_TOKEN=123 email raw [options] | ||
|
||
$ POSTMARK_ACCOUNT_TOKEN=123 servers list [options] | ||
``` | ||
|
||
If a token is not supplied as an environment variable, you will be prompted for the server or account token after running the command. | ||
|
||
<img src="./media/token-prompt.png" width="100%" style="max-width: 930px;"> | ||
|
||
## postmark email _<command>_ | ||
|
||
Send an email via Postmark. | ||
|
||
### raw [options] | ||
|
||
Send an email with the HTML or Text body defined. | ||
|
||
```bash | ||
$ postmark email raw --from="" --to="" --subject="howdy" --html="<h1>Hi there</h1>" --text="Hi there" | ||
|
||
# Options | ||
--from, -f Email address you are sending from. Must be an address on a | ||
verified domain or confirmed Sender Signature. | ||
[string] [required] | ||
--to, -t Email address you are sending to [string] [required] | ||
--subject The subject line of the email [string] [required] | ||
--html The HTML version of the email [string] | ||
--text The text version of the email [string] | ||
``` | ||
|
||
### template [options] | ||
|
||
Send a templated email. | ||
|
||
```bash | ||
$ postmark email template --alias="" --from="" --to="" --model='{"name": "Jane"}' | ||
|
||
# Options | ||
--id, -i Template ID [string] | ||
--alias, -a Template Alias [string] | ||
--from, -f Email address you are sending from. Must be an address on a | ||
verified domain or confirmed Sender Signature.[string] [required] | ||
--to, -t Email address you are sending to [string] [required] | ||
--model, -m [string] | ||
``` | ||
|
||
## postmark servers _<command>_ | ||
|
||
### list [options] | ||
|
||
Fetch a list of servers on an account. | ||
|
||
```bash | ||
$ postmark servers list | ||
|
||
# Options | ||
--count, -c Number of servers to return [number] | ||
--offset, -o Number of servers to skip [number] | ||
--name, -n Filter servers by name [string] | ||
``` | ||
|
||
## postmark templates _<command>_ | ||
|
||
Provides a push and pull workflow for your email templates. This lets you store your templates in version control and push to Postmark via a CI/CD pipeline. | ||
|
||
**⚠️ Before you get started**, make sure that all of your templates have an alias. Check out our [help doc](https://postmarkapp.com/support/article/1117-how-do-i-use-a-template-alias) for more info. | ||
|
||
### pull _<output directory>_ [options] | ||
|
||
Download templates from a Postmark server to your local file system. | ||
|
||
```bash | ||
$ postmark templates pull ~/Desktop/my_templates | ||
|
||
# Options | ||
--overwrite, -o Overwrite templates if they already exist | ||
[boolean] [default: false] | ||
``` | ||
Here’s an example of the directory structure that is downloaded: | ||
```bash | ||
my_templates | ||
├── password_reset | ||
│ ├── content.html | ||
│ ├── content.txt | ||
│ └── meta.json | ||
└── welcome | ||
├── content.html | ||
└── meta.json | ||
``` | ||
## Installation | ||
|
||
Each template is stored in its own subdirectory with the HTML and text content, and metadata. The metadata contains the template’s name, subject, and alias. | ||
**NOTE:** If you update the template alias in `meta.json`, be sure to rename the template’s directory so it matches. This prevents conflicts down the line when pulling templates. | ||
### push _<templates directory>_ [options] | ||
Pushes templates from the local file system to a Postmark server. | ||
```bash | ||
$ postmark templates push ~/Desktop/my_templates | ||
|
||
# Options | ||
--force, -f Disable confirmation before pushing templates [boolean] | ||
``` | ||
By default, you will be asked to confirm your changes before pushing your templates. | ||
<img src="./media/push-confirm.png" width="100%" style="max-width: 930px;"> | ||
- Install [Node.js](https://nodejs.org/en/) | ||
- `$ npm i postmark-cli -g` | ||
- `$ postmark` 🌈 | ||
|
||
You can force push templates which disables the confirmation by including the `-f` flag. | ||
## Issues & Comments | ||
|
||
```bash | ||
$ postmark templates push ~/Desktop/my_templates -f | ||
``` | ||
Feel free to contact us if you encounter any issues with the library. | ||
Please leave all comments, bugs, requests and issues on the Issues page. | ||
|
||
# License | ||
## License | ||
|
||
The MIT License (MIT) 2019 [Wildbit](https://wildbit.com). Please have a look at the [LICENSE.md](LICENSE.md) for more details. | ||
Postmark CLI library is licensed under the **MIT** license. Please refer to the [LICENSE](https://github.com/wildbit/postmark-cli/blob/master/LICENSE.md) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
{ | ||
"SERVER_TOKEN" : "<token>", | ||
"ACCOUNT_TOKEN" : "<token>" | ||
"FROM_ADDRESS" : "<from_email@address>" | ||
"TO_ADDRESS" : "<to_email@address>" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import {expect} from "chai"; | ||
import "mocha"; | ||
import * as execa from 'execa' | ||
import {serverToken, fromAddress, toAddress, CLICommand} from "./shared"; | ||
import * as postmark from 'postmark'; | ||
|
||
describe("Email send template command", () => { | ||
const options: execa.CommonOptions = {env: {'POSTMARK_SERVER_TOKEN': serverToken}}; | ||
|
||
const toParameter = `--to=${toAddress}`; | ||
const fromParameter = `--from=${fromAddress}`; | ||
const baseParameters = ['email', 'template']; | ||
const defaultParameters = baseParameters.concat([toParameter, fromParameter]); | ||
|
||
const client: postmark.ServerClient = new postmark.ServerClient(serverToken); | ||
|
||
describe("not valid", () => { | ||
it('no arguments', () => { | ||
return execa(CLICommand, baseParameters, options).then((result) => { | ||
expect(result).to.equal(null); | ||
}, (error) => { | ||
expect(error.message).to.include('Missing required arguments: from, to'); | ||
}); | ||
}); | ||
|
||
it ('no model', async () => { | ||
const templates: postmark.Models.Templates = await client.getTemplates(); | ||
const parameters: string[] = defaultParameters.concat(`--id=${templates.Templates[0].TemplateId}`); | ||
|
||
try { | ||
await execa(CLICommand, parameters, options); | ||
throw Error('make sure error is thrown') | ||
} catch (error) { | ||
expect(error.message).to.include('ApiInputError'); | ||
} | ||
}); | ||
|
||
it ('no template id', async () => { | ||
try { | ||
await execa(CLICommand, defaultParameters, options); | ||
throw Error('make sure error is thrown') | ||
} catch (error) { | ||
expect(error.message).to.include('ApiInputError'); | ||
} | ||
}); | ||
}); | ||
|
||
|
||
describe("valid", () => { | ||
it ('send with template id', async () => { | ||
const templates: postmark.Models.Templates = await client.getTemplates(); | ||
const extraParameters: string[] = [`--id=${templates.Templates[0].TemplateId}`, '--m={}'] | ||
const parameters: string [] = defaultParameters.concat(extraParameters); | ||
const {stdout} = await execa(CLICommand, parameters, options); | ||
|
||
expect(stdout).to.include("\"Message\":\"OK\""); | ||
}); | ||
}); | ||
}); | ||
|
Oops, something went wrong.