# Log mail DNS changes in D1 and notify Slack

Watch a domain’s MX, SPF and DMARC records. Save each observed change in D1 and send the previous and current settings to a Slack channel.

[Use template](https://dashboard.fasthook.io/workflow/new?templateKey=cloudflare-dns-mail-changes-to-d1-and-slack&templateName=Log+mail+DNS+changes+in+D1+and+notify+Slack)

**Required accounts**

- Cloudflare DNS
- Cloudflare D1
- Slack

## Log mail DNS changes in D1 and notify Slack

### 1. Trigger · Mail routing or authentication changed

**Cloudflare DNS**. Start when the observed MX, SPF or DMARC records differ from the previous check. The first check saves a baseline.

### 2. Action · Record the observed change once

**Cloudflare D1**. Run a statement with bound values, or send a batch. Each row in the results uses the column names from your query.

### 3. Action · Send the changed mail settings to Slack

**Slack**. Send text, Block Kit content, attachments, or a thread reply to a channel.

## Set up your workflow

1. **Choose the mail domain** Connect Cloudflare, enter the zone ID and the full mail domain in the trigger. Allow the first poll to establish a baseline of the MX, SPF and DMARC settings.
2. **Create the change history table** Run this statement once in the selected D1 database: CREATE TABLE IF NOT EXISTS dns\_mail\_changes (change\_id TEXT PRIMARY KEY, domain TEXT NOT NULL, previous TEXT, current TEXT NOT NULL, observed\_at TEXT NOT NULL). Select the same database in the workflow. Each change ID can be inserted once.
3. **Choose the destination channel** Connect Slack, select your channel and invite the bot if the channel is private. Alerts include both sets of observed values.
4. **Check a change** Use a test subdomain and edit one mail record after the baseline. Compare the Slack notification with the D1 row and let an unchanged poll pass. Changes between polls can be missed.

## Related integrations

- [Cloudflare DNS integrations](https://www.fasthook.io/apps/cloudflare-dns/integrations)
- [Cloudflare D1 integrations](https://www.fasthook.io/apps/cloudflare-d1/integrations)
- [Slack integrations](https://www.fasthook.io/apps/slack/integrations)
