# gcp-function-mailer

> Google Cloud Library that creates Cloud Functions for sending email via Sendgrid

Latest version **0.3.2** (published 2018-01-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install gcp-function-mailer
pnpm add gcp-function-mailer
yarn add gcp-function-mailer
bun add gcp-function-mailer
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2018-01-30 |
| First published | 2018-01-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jon Williams |
| Maintainers | jonathannen |

## Links

- npm: https://www.npmjs.com/package/gcp-function-mailer
- npm.io page: https://npm.io/package/gcp-function-mailer

## Dependencies (3)

- [mustache](https://npm.io/package/mustache.md) ^2.3.0
- [deepmerge](https://npm.io/package/deepmerge.md) ^2.0.1
- [@sendgrid/mail](https://npm.io/package/@sendgrid/mail.md) ^6.2.1

## Recent versions

- 0.3.2 (latest) — 2018-01-30
- 0.3.1 — 2018-01-30
- 0.3.0 — 2018-01-30
- 0.2.0 — 2018-01-30
- 0.1.2 — 2018-01-29
- 0.1.1 — 2018-01-29
- 0.1.0 — 2018-01-29

## README

# GCP Function Mailer

Sends an email using the Sendgrid API using a Google Cloud Platform (GCP) Function. The data and trigger for the email is a GCP Pubsub message. It gets formatted to HTML and/or Text using a given mustache template.

See the example under the example directory for usage.

## Quickstart

    mkdir your-mailer-directory
    cd your-mailer-directory
    npm init .
    npm install gcp-function-mailer --save
    cp config.json config.production.json
    touch hello.text.mustache
    touch hello.html.mustache

Edit the config.production.json file to include the Sendgrid API key you want to use in production. Then edit the two mustache templates. The first line of the template should be the subject as a string.

To deploy to Google Cloud, set up your gcloud environment and run:

    gcloud beta functions deploy mailer --trigger-topic=mailer

You can trigger the function in either the Google Cloud Console or via the command line:

    gcloud beta functions call mailer --data '{"template":"hello", "to":"jon@example.org"}'

## Configuration

Configuration data is taken from a number of sources. The code will attempt to load the local config.json and config.[NODE_ENV].json files. It will also load package.json and look for the "mailer key". These values are combined with any configuration supplied programattically. Generally all you will need is a config.json for local development and a production version.

Don't check in your production version. Right now there isn't an easy mechanism for secrets configuration for Google Cloud Functions. However, this is [in progress with Google](https://issuetracker.google.com/issues/35907643).

The configuraton must contain a sendgridApiKey, unless it can be sourced from the SENDGRID_API_KEY environment variable.

The configuration can contain: `defaultCc`, `defaultBcc`, `defaultFrom`, and `defaultReplyTo` values.

## Invoking

To send an email, publish a message to the mailer pubsub topic.

Each invocation must have a `to` and `template` value. It can optionally contain `cc`, `bcc`, `from` and `replyTo` values.

The whole message is supplied to the Mustache template for rendering.

## Templates

The code assumes the first line of the template is the subject line for the email. If you have both HTML and Text templates, the Text subject line takes precidence. So you can leave the HTML one blank if that suits - but the line must still be present.

---
_Source: https://npm.io/package/gcp-function-mailer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
