This is a vary basic webhook server built with TypeScript and Express. It can be configured with a self-hosted Ghost instance to batch emails and send them via a third-party email provider (other than Mailgun).
Ghost CMS is a great, FOSS blogging platform, but it lacks the ability to batch emails and send them via third-party email providers other than Mailgun. This webhook server can be used to add this functionality to a self-hosted Ghost instance. I plan to provide a proper implementation of this functionality within the Ghost app in the future and present as a PR to the team, but for now, this is a fine solution.
- Go to your Ghost admin panel and navigate to the "Integrations" tab.
- Click the "Add custom integration" button.
- Give the integration a name (e.g. "Email Batcher") and click the "Create" button.
- Click the "Add Webhook" button.
- Select the "Post published" event.
- Enter the URL of the webhook server (e.g. http://localhost:3000/webhook) and click the "Save" button.
Sending your posts out via email when you publish them is not an option unless you have configured Mailgun in the email newsletter section of the Ghost admin panel. Obviously we don't have Mailgun credentials, so we need to fake it. To do this, follow these steps:
- Go to "Settings" in the Ghost admin panel.
- Click the "Email Newsletter" tab.
- Under General Settings, expand the "Mailgun" section.
- Enter fake values into the "Mailgun Domain" and "Mailgun Private API Key" fields. Seriously.
- Locally
- Docker
The following environment variables are required regardless of which installation method you choose:
- EMAIL_PROVIDER: The email provider to use. Currently supported providers are postmark and sendgrid.
- MAIL_SERVER_API_KEY: The API key for the email provider.
- MAIL_TEMPLATE_ID: The ID of the email template from whichever 3rd party provider to use for the emails.
- DATABASE_CONTAINER_NAME: The name of the MySQL database container.
- MYSQL_USER: The username for the MySQL database.
- MYSQL_PASSWORD: The password for the MySQL database.
- MYSQL_DATABASE: The name of the MySQL database.
- Clone the repository to your local machine.
- Navigate to the root directory of the project.
- Install the required dependencies by running
npm install
- Set the required environment variables by creating a
.env
file in the root directory of the project. - Start a dev version of the application by running
npm start
. - You can also build a production version of the application by running
npm run build
and then runnode dist/ghost_hooks.js
to start the server.
- Clone the repository to your local machine.
- Navigate to the root directory of the project.
- Set the required environment variables by creating a
.env
file in the root directory of the project. - Build the Docker image by running
docker build -t ghost-email-batcher .
- Run the Docker image by running
docker run -d -p 3000:3000 ghost-email-batcher
To use the application, follow these steps:
- Create a new post in Ghost
- Click the "Publish" button
- Select the option to publish the post and send it via email
- Any members that have signed up for that newsletter should receive the post via email
- This is a janky way to go about this. You can read more about my decision to take this approach in my blog post.
- Access to the Ghost database is required for this server to work properly.
- There is no email tracking or analytics available at this time. This is technically possible via deeper integration with third party providers, but it wouldn't ever be integrated into the Ghost admin panel via this webhook, so I've deliberately left it out.
- All of your posts which use this flow will report as having "failed to send" in the Ghost admin panel. This is because the webhook server is sending the emails, not Ghost. 🤷♂️
If you would like to contribute to the application, please follow these steps:
- Fork the repository to your own GitHub account.
- Create a new branch for your changes.
- Make your changes and commit them to your branch.
- Push your branch to your forked repository.
- Create a pull request to merge your changes into the main repository.
This application is licensed under the MIT License. See the LICENSE file for more information.