- NodeJs (>= 6.0)
- MongoDB (>= 3.4)
It is assumed you have MongoDB installed already. If not, install MongoDB. Note that MongoDB must be publicly accessible via an IP or domain if you are using Google Cloud HTTP function to handle your webhooks (see Webhook Setup). If you can, I recommend you host MongoDB on a separate server.
- Create directory locally or on your server
- Run
git clone https://github.com/suetco/suet
in the directory or just download and unzip right in - Run
npm install
Next, you will need to update the environment variables. There is a .env.example
file that contains the needed variables. These variables also include settings for third party tools and services Suet uses. These are:
- Bugsnag for error reporting
- Elasticsearch for search
- Mailgun for sending password recovery mails. In coming versions, provision will also be made to use SES
- Slack for complaints and failure deliveries
Open the file, edit the variables and rename the file to .env
. They variables are:
HOST
- The IP or web address your application will be located at, without the trailing slash. Must include the protocol (http or https) even if it is an IP e.g. http://suet.some.paasSESSION_KEY
- Random string to encrypt session cookiesAES_KEY
- Random string used for API key encryption in the database. It is important you don’t change this key once set as already encrypted keys will not be decryptableDB_NAME
- Name of your MongoDB database e.g suetDB_URL
- URL of your MongoDB database e.g mongodb://localhost/suetES_HOST
- Elasticsearch IP or web addressES_AUTH
- httpAuth value for your ElasticsearchBS_KEY
- Bugsnag key for error reporting. Signup for a free account at bugsnag.com and get a keyEMAIL_FROM
- The sender identification for the email. Format “Name <email>” e.g. Suet <[email protected]>EMAIL_DOMAIN
- The Mailgun domain you want to send emails fromEMAIL_KEY
- The API key of the domain above. Login to your Mailgun account and click the domain to get the domain API keyWEBHOOK
- Your Mailgun webhook URL. See Webhook Setup.SLACK_CLIENT_ID
- Your Slack app’s client ID. See Connecting SlackSLACK_CLIENT_SECRET
- Your Slack app’s client secret. See Connecting Slack)SES_CONFSET
- Configuration set name for SES. You don’t need to change this.SES_TOPIC
- A name to create the notification topic. You also don’t need to change this.SES_WEBHOOK
- Your SES webhook. See Webhook Setup.
Once set (and file renamed to .env
), you can start Suet with node app.js
or in your favourite way.
One important change to version 2 is that API keys are encrypted (AES, 256, CTR) in the DB. If you are upgrading from v1, you need to run node upgrades/v2.js
to encrypt existing keys in your database. Don’t forget that once this is done, you shouldn’t change your AES_KEY
any longer as already encrypted keys will not be decryptable.
You need to setup webhooks that Mailgun and SES will send events to. (Here is a post on working with Mailgun webhooks). The recommended option for the Mailgun webhook is to use Google Cloud HTTP function. It is highly scalable especially if you send lots of mails.
Q: Why not AWS API gateway + Lambda?
A: Mailgun uses the content-type multipart/form-data to send some event data and this content-type is not supported by AWS API gateway (yet).
If microservices is not your thing or just can't go through the stress, the webhook endpoints are available at [host]/mailgun/webhook
and [host]/ses/webhook
. This is discussed further below.
- Go to your Google Cloud Console (if you don't have an account yet, create one).
- Enable Cloud functions in the dashboard.
- Click on Create Function.
- You will repeat these steps twice to create the SES and Mailgun webhooks. Enter your preferred name for the webhook (e.g ses-webhook or mg-webhook).
- In the trigger section, select HTTP trigger. Note the URL, that will be your webhook URL.
- Edit
workers/hooks/index.js
and enter your MongoDB URL. (No environment variable in Google cloud or I wasn’t looking well enough). - Also enter the HOST variable (as defined in your environment variable above). This is used to create mail links sent to Slack.
- Copy the content of the file and paste in the index.js section of the Cloud function.
- Copy the content of
workers/hooks/package.json
and paste in the package.json section. - Select or create a Stage bucket. The stage bucket is simply where the code is staged. You can use anything here.
- In Function to execute, enter
handler
. - Save.
Edit your the WEBHOOK
and SES_WEBHOOK
variables to point to [host]/mailgun/webhook
and [host]/ses/webhook
respectively. Remember, the host [host] value should include the protocol (http or https) even if it is an IP.
You can connect Slack to Suet to be able to receive complaint, bounce and fail notifications. To do this you need to create a Slack app and add the details to Suet. Once added, domains can be connected to Slack in the domain settings page of the Suet dashboard.
- Visit api.slack.com/apps and click on the
Create New App
button. - Enter the required details and proceed.
- Under the
Add features and functionality
section, click onIncoming Webhooks
. - Activate Incoming Webhooks in the next page (toggle the switch to
On
) then go back to previous page. - Scroll down to
App Credentials
and copy your Client ID and Client Secret. - Use the credentials as your Slack environment variables.