Setup Ghost Webhook for Custom Email Newsletter
Tags: ghost, email, newsletter, webhooks
Published: 2022-08-04 09:52:58

---
title: Setup Ghost Webhook for Custom Email Newsletter
published: true
date: 2022-07-29 05:24:59 UTC
tags: ghost, email, newsletter, webhooks
canonical_url: 
---

Hello people,

This guide is to set up and send the newsletter to subscribers in [Ghost](https://ghost.org) cms with Custom Webhook support. As you know Ghost provides only integration of [Mailgun](https://www.mailgun.com) and they don't have a free tier or simply say costly pricing structure for me.

So I needed an alternate approach from many of [proposed solutions](https://ghost.org/docs/faq/mailgun-newsletters/). I have tried with Zappier Gmail integration but it was causing the same issue that will occur in this setup too. I opened a discussion regarding that in [Ghost Forum](https://forum.ghost.org/t/ghost-newsletter-mail-for-any-email-service-integration/30779) but no response till now.

Anyway, We will try a custom solution with Webhooks. There any many webhooks available in Ghost that you can build your custom solution or integration as needed. This guide follows a self-hosted Ghost instance on a cloud server, not a managed one. Let's begin.

### Step 1: Ghost Webhooks

Refer to this [Offical Webhook Doc - Ghost](https://ghost.org/docs/webhooks/) to understand and see a list of available webhooks in Ghost, their triggers and which to use.

### Step 2: Create New Integration

From Ghost Admin, Goto **Settings** -> **Integrations**. Click on the **Add Custom integration** Button and you will see the below dialogue. ![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1659003388539/jW_Nu64a_6.png)In this dialogue give the name of your integration(e.g Custom Email hooks) or whatever you want like Newsletter something and click Create.

### Step 3: Configure your Integration

When you click on **Create** you will be redirected to the configuration page, where you have two sections. Configuration and Webhooks.

#### 3.1 Basic Configuration

In the Configuration section, you can add/update things like Name, Description, and Icon of Integration. Other important things are credentials like Content API key, Admin API key and API URL as below. You can regenerate API keys if you want in case of loss/compromise. ![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1659003941473/m1IAinlC8.png)

#### 3.2 Add New webhook

Click on the **Add webhook** button to create a new webhook where you'll see the following popup. Add **Name** of the hook, Select **Event** e.g I have selected _Page Published_ event from many available because we want to trigger an event when a page is published and send a mail with our custom logic and finally set **Target URL** where you want to pass webhook payload which will further process it and send mail, it can be any running server/less API. Click on Create and your webhook should be created.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1659004081521/9Ax-bQ76I.png)

#### 3.3 Review/Update Webhooks

When you create a webhook you will see it is listed here, all your webhooks are listed here in this specific integration. From here you can edit/edit webhook, and see when was last it was triggered and other basic information.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1659004176856/mqWwQChmp.png)

**Notes:**

- As Ghost is tightly coupled with Mailgun, and in most releases, their features are also connected to it e.g during publishing a post you can't send Newsletter if Mailgun is not configured. 
- With this setup, you won't be able to see stats of emails/newsletters-related stuff, If I say simply that you can only send emails when specified webhook triggers.
- As I said earlier, when you send a mail with this you'll lose CSS/UI in the mail, but you can build an email template for this by referring to internal logic in Ghost.
- In this, my newsletter emails are sent using NodeMailer with Gmail(SMTP), which should not be used in production, but implement queue management or an alternate approach on the server side.

Thank you for reading this article, I hope this guide was informative and useful to you, please like/share and leave your feedback.