An HTTP interface to send emails using an internal SMTP server.
This application provides a way for pages applications to send emails via the cloud.gov smtp server without each space having access to the required ASG. It is only accessible on the internal network and requires basic authentication.
To use pages-mailer
:
-
create a
network-policy
on cloud.gov to allow container to container networking:# target the space containing the target app cf target -s <target-space> # add the network policy cf add-network-policy <target-app-name> pages-mailer -s email -o gsa-18f-federalist
-
include basic authentication credentials that match those in the
auth
user-provided-service inemail
space -
send a POST request to the
/send
endpoint with required json data
curl -X POST \
-H "Content-Type: application/json" \
-u '<username>:<password>' \
-d '{ "html": "<h1>Some Email Content</h1>", "subject": "Email Subject", "to": ["[email protected]"] }' \
http://pages-mailer.apps.internal:8080/send
Note: specying the port is required to reach the application over the internal network.
The application can be configured via the following environment variables:
Variable | |
---|---|
AUTH_USERNAME | Basic authentication username |
AUTH_PASSWORD | Basic authentication password |
CF_INSTANCE_CERT | SSL Certificate (optional to support ssl) |
CF_INSTANCE_KEY | SSL Certificate Key (optional to support ssl) |
FROM | Email address to send emails from |
HOST | Host for the http server |
PORT | Port for the http server |
SMTP_CERT | Certificate chain to trust for SMTP server |
SMTP_HOST | Hostname of SMTP server |
SMTP_PASSWORD | Password for authentication with SMTP server |
SMTP_PORT | Port for SMTP server |
SMTP_USER | Username for authentication with SMTP server |
TRANSPORT | The mailer transport: 'smtp' (leave empty for json) |
Configuration on cloud.gov is provided 2 ways:
Via environment values listed under the env
key in the manifest.
Via cloud.gov services
which are also listed under the services
key in the manifest.
Values provided via cloud.gov services
are mapped to ordinary environment variables before the application starts, see .profile for details.
This application leverages Concourse for its deployment
automation, but it's not dependent on it. You can find example and live
concourse configuration files in the ci/
directory.
node 18.17
npm 7.x
git clone [email protected]:cloud-gov/pages-mailer.git
cd pages-mailer
npm install
cp sample.env .env
npm run dev
npm test
npm run lint