项目作者: MatthiasKunnen

项目描述 :
Publish your emails to SparkPost automatically
高级语言: TypeScript
项目地址: git://github.com/MatthiasKunnen/sparkpost-publisher.git
创建时间: 2018-06-14T14:11:45Z
项目社区:https://github.com/MatthiasKunnen/sparkpost-publisher

开源协议:ISC License

下载


npm version
Build Status
Build Status

SparkPost publisher

This library allows you to publish your emails to SparkPost automatically. No
longer you need to copy paste your emails to SparkPost and mistakenly update the
wrong template. A version controlled single source of truth for your emails.

Made for Foundation for Emails but can be used for other frameworks such as
MJML.

The library works by mapping your generated email files to a SparkPost template
using a JSON file called sparkpost-map.json. It is also possible to specify
the name and path of the file.

Basic example:

  1. {
  2. "password-reset": {
  3. "config": {
  4. "html": {
  5. "file": "password-reset.html"
  6. }
  7. },
  8. "sparkpost": {
  9. "content": {
  10. "from": {
  11. "email": "no-reply@example.com",
  12. "name": "Example.com"
  13. },
  14. "subject": "Password reset"
  15. },
  16. "options": {
  17. "transactional": true
  18. }
  19. }
  20. }
  21. }

The keys of the root object are the IDs of the templates in SparkPost. If the ID
does not exist, the template will be created.

The config key contains the configuration used by this library.

Config explained:

  1. {
  2. "html": {
  3. "file": "password-reset.html"
  4. },
  5. "email_rfc822": {
  6. "file": "password-reset.rfc"
  7. },
  8. "text": {
  9. "file": "password-reset.txt"
  10. }
  11. }

This config object means the following:

  • replace content.html with the contents of the file found at
    dist/password-reset.html.
  • replace content.email_rfc822 with the contents of the file found at
    dist/password-reset.rfc.
  • replace content.text with the contents of the file found at
    dist/password-reset.txt.

While you can use both html and text if desired, you cannot mix either of
them with email_rfc822.

The config.content object is essentially merged into the sparkpost.content
object after the source files are read.

The sparkpost key contains any template configuration you would like to
specify. This allows you to version control name, description and other options
of your templates. Add any configuration as described in
https://developers.sparkpost.com/api/templates.html#header-template-attributes.
Do NOT specify the published field or any readonly fields as this will cause
errors.

Usage

Publish

Publish all your emails using the
spp publish --api-key your-api-key-here
command. Optionally, you can specify that you only wish to publish one email
using the --template template-id flag. New templates will be created and
published.

Endpoint and API version

Endpoint and api version can be configured using --endpoint and --api-version.

Multiple environments, review/staging

If you have multiple environments you can use the suffix flag to deploy your
templates with a suffix.

E.g. using --suffix review with template password-reset will create or
update a template with the ID of password-reset-review.

Draft

Submit your drafts using the
spp draft command with the same options as the
publish command.

Verbose

Add the -v flag for more verbosity. Helpful to identify any errors.

Permissions

The SparkPost API key needs the following permissions:

  • Templates: Read/Write