Postgres + Stripe: churn risk emails sent via Gmail
Your “at-risk customer” list is probably a mess. Usage lives in Postgres. Billing context lives in Stripe. And the actual outreach happens… when someone remembers to do it.
This Stripe churn emails automation hits SaaS founders first, because retention is oxygen. But marketing leads and client-facing ops folks feel it too. You get a consistent churn-risk email motion running from real usage signals, not vibes.
This guide breaks down the exact n8n workflow: pull customer metrics from Postgres, enrich with Stripe data, then send the right Gmail message to the right segment automatically.
How This Automation Works
Here’s the complete workflow you’ll be setting up:
n8n Workflow Template: Postgres + Stripe: churn risk emails sent via Gmail
flowchart LR
subgraph sg0["Daily Revenue Analysis Flow"]
direction LR
n0@{ icon: "mdi:play-circle", form: "rounded", label: "Daily Revenue Analysis", pos: "b", h: 48 }
n1@{ icon: "mdi:swap-vertical", form: "rounded", label: "Revenue Settings", pos: "b", h: 48 }
n2["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/postgres.svg' width='40' height='40' /></div><br/>Get Customer Analytics"]
n3["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/code.svg' width='40' height='40' /></div><br/>Analyze Revenue Opportunities"]
n4@{ icon: "mdi:swap-horizontal", form: "rounded", label: "Filter High Risk Customers", pos: "b", h: 48 }
n5["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/httprequest.dark.svg' width='40' height='40' /></div><br/>Get Customer Details"]
n6@{ icon: "mdi:message-outline", form: "rounded", label: "Send Retention Campaign", pos: "b", h: 48 }
n7@{ icon: "mdi:swap-horizontal", form: "rounded", label: "Filter Upsell Opportunities", pos: "b", h: 48 }
n8["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/httprequest.dark.svg' width='40' height='40' /></div><br/>Get Customer Details1"]
n9@{ icon: "mdi:message-outline", form: "rounded", label: "Send Upsell Campaign", pos: "b", h: 48 }
n10@{ icon: "mdi:swap-horizontal", form: "rounded", label: "Filter Re-engagement Needed", pos: "b", h: 48 }
n11["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/httprequest.dark.svg' width='40' height='40' /></div><br/>Get Customer Details2"]
n12@{ icon: "mdi:message-outline", form: "rounded", label: "Send Re-engagement Campaign", pos: "b", h: 48 }
n1 --> n2
n5 --> n6
n8 --> n9
n11 --> n12
n0 --> n1
n2 --> n3
n4 --> n5
n10 --> n11
n7 --> n8
n3 --> n4
n3 --> n7
n3 --> n10
end
%% Styling
classDef trigger fill:#e8f5e9,stroke:#388e3c,stroke-width:2px
classDef ai fill:#e3f2fd,stroke:#1976d2,stroke-width:2px
classDef aiModel fill:#e8eaf6,stroke:#3f51b5,stroke-width:2px
classDef decision fill:#fff8e1,stroke:#f9a825,stroke-width:2px
classDef database fill:#fce4ec,stroke:#c2185b,stroke-width:2px
classDef api fill:#fff3e0,stroke:#e65100,stroke-width:2px
classDef code fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
classDef disabled stroke-dasharray: 5 5,opacity: 0.5
class n0 trigger
class n4,n7,n10 decision
class n2 database
class n5,n8,n11 api
class n3 code
classDef customIcon fill:none,stroke:none
class n2,n3,n5,n8,n11 customIcon
Why This Matters: Churn Signals Get Missed (Until It’s Too Late)
Churn rarely happens “all at once.” It shows up as a pattern: fewer logins, a key feature goes unused, seats drop, invoices start failing, or a plan quietly downgrades. The painful part is you usually have the data, just not in the same place at the same time. So you end up chasing symptoms in spreadsheets, pulling Stripe details on demand, and writing “just checking in” emails that land too late to matter. And honestly, once the habit becomes reactive, it’s hard to climb out.
It adds up fast. Here’s where it breaks down in real teams.
- Someone has to manually pull Postgres usage metrics, which turns into a weekly ritual nobody enjoys.
- Billing context gets checked customer-by-customer in Stripe, so outreach depends on how busy the day is.
- Segments drift because the “at risk” definition changes, but the spreadsheet filter never does.
- Emails go out inconsistently, which means you can’t tell what actually improved retention.
What You’ll Build: Usage + Billing Intelligence That Sends the Right Email
This workflow runs on a schedule and does the work you normally do in fragments. First, it pulls customer usage and engagement signals from Postgres (the stuff that hints someone is drifting). Then it runs that data through a scoring step to decide what each account needs next: retention intervention, an upsell nudge, or a reactivation check-in. For each segment, the workflow fetches the customer’s Stripe context (so you’re not emailing blindly) and sends a targeted message through Gmail. The output is simple: the right customer gets the right email at the right time, without you building a new list every week.
The flow starts with a scheduled review, then a configuration step that sets thresholds and rules. After analysis, three filters route customers into retention, upsell, or re-engagement paths. Each path enriches the customer record from Stripe and sends a Gmail email that matches the situation.
What You’re Building
| What Gets Automated | What You’ll Achieve |
|---|---|
|
|
Expected Results
Say you review churn risk for 120 customers every week. Manually, you might spend about 3 minutes pulling usage per customer from Postgres and another 2 minutes checking Stripe, which is roughly 10 hours before you even write an email. With this workflow, the weekly run happens automatically, and you only step in for the handful of accounts that need human attention (maybe 10–20). That can turn a half-day retention chore into a quick review.
Before You Start
- n8n instance (try n8n Cloud free)
- Self-hosting option if you prefer (Hostinger works well)
- Postgres for customer usage and engagement metrics.
- Stripe to pull billing and customer context via API.
- Gmail to send retention, upsell, and reactivation emails.
- OpenAI API key (get it from the OpenAI dashboard) for AI-assisted copy or summaries.
Skill level: Intermediate. You’ll connect credentials and confirm your Postgres query and Stripe fields match your data model.
Want someone to build this for you? Talk to an automation expert (free 15-minute consultation).
Step by Step
A scheduled review kicks it off. n8n runs this workflow on a cadence you choose (weekly is common). That way churn monitoring becomes a system, not a calendar reminder.
Usage signals are pulled from Postgres. The workflow queries your database for customer metrics that correlate with churn or expansion. This could be logins, key event counts, feature adoption, seat changes, or any “health score” fields you already maintain.
An analyzer scores and routes accounts. A processing step evaluates each customer and sends them down one of three paths: retention risk, upsell candidates, or reactivation-needed. Those “If” filters are where your definition of risk actually lives.
Stripe enrichment plus Gmail outreach happens automatically. For each path, n8n calls Stripe via HTTP to fetch customer details (plan, status, recent billing events), then sends a Gmail email using the right message template for that situation.
You can easily modify the routing rules to match your product’s reality, then adjust email content based on segment and plan tier. See the full implementation guide below for customization options.
Step-by-Step Implementation Guide
Step 1: Configure the Schedule Trigger
Set the workflow to run on a fixed schedule so revenue engagement is evaluated automatically.
- Add the Scheduled Revenue Review node as your trigger.
- Set the Rule to a cron expression with Field =
cronExpressionand Value =0 6 * * *. - Connect Scheduled Revenue Review to Revenue Configurator.
Step 2: Connect PostgreSQL
Configure the revenue settings and load customer analytics data from your database.
- In Revenue Configurator, add number values for churnRiskThreshold =
0.7, upsellThreshold =0.8, and retentionDiscount =25. - Open Retrieve Customer Metrics and set Query to
SELECT customer_id, usage_score, engagement_score, support_tickets, payment_history, plan_type, mrr FROM customer_analytics WHERE active = true. - Credential Required: Connect your Postgres credentials in Retrieve Customer Metrics.
- Connect Revenue Configurator to Retrieve Customer Metrics.
Step 3: Set Up Revenue Opportunity Analyzer
Analyze each customer’s churn risk and upsell potential to determine the correct engagement path.
- Open Revenue Opportunity Analyzer and paste the full JavaScript logic for churn risk and upsell scoring (provided in the workflow).
- Verify the node references
$node['Revenue Configurator'].jsonfor threshold values. - Connect Retrieve Customer Metrics to Revenue Opportunity Analyzer.
Revenue Opportunity Analyzer outputs to Retention Risk Filter, Upsell Candidate Filter, and Reactivation Need Filter in parallel.
Tip: Keep the field names in the database query aligned with the analyzer code (e.g., usage_score, engagement_score, mrr), or the scoring logic will default values to zero.
Step 4: Configure Branch Filters and Stripe Lookups
Route each customer to the appropriate engagement campaign and enrich data from Stripe.
- In Retention Risk Filter, set the condition to Left Value =
{{ $json.recommended_action }}and Right Value =retention_campaign. - In Upsell Candidate Filter, set the condition to Left Value =
{{ $json.recommended_action }}and Right Value =upsell_campaign. - In Reactivation Need Filter, set the condition to Left Value =
{{ $json.recommended_action }}and Right Value =engagement_campaign. - In Fetch Stripe Customer, set Method to
GET, URL tohttps://api.stripe.com/v1/customers/{{ $json.customer_id }}, and add an Authorization header withBearer {{ $credentials.stripe.secretKey }}. - Repeat the same Stripe settings for Fetch Stripe Customer 2 and Fetch Stripe Customer 3.
- Credential Required: Connect your Stripe credentials for the HTTP Request nodes (Stripe secret key is referenced in the Authorization header).
⚠️ Common Pitfall: If the Stripe authorization header is missing or the credential name does not match $credentials.stripe.secretKey, the customer lookup will fail and no emails will be sent.
Step 5: Configure Email Outputs
Send personalized campaigns based on the routing decisions and Stripe-enriched customer data.
- In Dispatch Retention Email, set Send To to
{{ $json.email }}and Subject toSpecial Offer - We Value Your Business 💎. - Ensure the retention email body includes the expressions
{{ $node['Revenue Configurator'].json.retentionDiscount }}and{{ $node['Revenue Opportunity Analyzer'].json.customer_id }}. - In Dispatch Upsell Email, set Send To to
{{ $json.email }}and Subject toReady to Unlock More Value? 🚀. - In Dispatch Reengagement Email, set Send To to
{{ $json.email }}and Subject toWe Miss You! Let's Get You Back on Track 🎯. - Credential Required: Connect your Gmail credentials in all three email nodes: Dispatch Retention Email, Dispatch Upsell Email, and Dispatch Reengagement Email.
Tip: The email nodes rely on $json.email returned from Stripe. Make sure your Stripe customer objects contain an email address.
Step 6: Test and Activate Your Workflow
Run a manual test to validate the end-to-end flow before turning on the schedule.
- Click Execute Workflow and confirm Retrieve Customer Metrics returns active customer rows.
- Verify Revenue Opportunity Analyzer outputs fields like
recommended_action,churn_risk, andupsell_potential. - Confirm each path runs: customers should pass through the correct filter node and into the corresponding Stripe lookup and email node.
- Check your inbox for sample emails sent by Dispatch Retention Email, Dispatch Upsell Email, or Dispatch Reengagement Email.
- When results look correct, switch the workflow to Active so Scheduled Revenue Review runs daily at 06:00.
Troubleshooting Tips
- Stripe HTTP credentials can fail because the API key is wrong or restricted. Check your Stripe Developers → API keys page, then confirm the key in n8n is the same environment (test vs live).
- If your Postgres query returns no rows, downstream filters may behave like “nothing is at risk,” which is misleading. Start by validating the SQL query in your database client, then paste it into the Postgres node.
- Gmail sending can silently hit limits or require the right OAuth permissions. If emails stop sending, inspect the Gmail node execution output and re-authenticate the Gmail credential in n8n.
Quick Answers
About an hour if your Postgres and Stripe fields are straightforward.
No. You’ll mainly connect accounts, paste/adjust a Postgres query, and edit your email copy.
Yes. n8n has a free self-hosted option and a free trial on n8n Cloud. Cloud plans start at $20/month for higher volume. You’ll also need to factor in OpenAI API costs (often just a few dollars a month at modest volume) if you use the AI Agent for writing or summaries.
Two options: n8n Cloud (managed, easiest setup) or self-hosting on a VPS. For self-hosting, Hostinger VPS is affordable and handles n8n well. Self-hosting gives you unlimited executions but requires basic server management.
Yes, and you should. Most customizations happen in the Postgres “Retrieve Customer Metrics” step and the three filters (Retention Risk Filter, Upsell Candidate Filter, Reactivation Need Filter). You can also swap the Stripe HTTP request to pull different billing fields, then tailor the Gmail subject and body for different plan tiers, regions, or customer segments.
Usually it’s an invalid or expired Stripe API key, or the request is pointed at the wrong environment. Regenerate the key in Stripe, update it in the HTTP Request credential, and re-run a single execution to confirm. If it still fails, check for missing permissions, bad customer IDs coming from Postgres, or rate limits if you’re pulling a lot of customers in one run.
A few hundred customers per run is typical, and more is possible. On n8n Cloud, your monthly execution limit depends on plan, while self-hosting has no hard execution cap (your server becomes the limit). If you’re emailing at scale, Gmail sending limits are usually the first bottleneck, so many teams throttle sends or split segments across days.
Often, yes, because this kind of churn workflow needs branching logic and data shaping, and n8n handles that without turning it into a pricing puzzle. Pulling from Postgres, scoring accounts, then routing into three different email paths is doable in Zapier/Make, but it can get brittle as rules change. n8n also gives you a self-hosting option, which matters when runs get frequent. If you only need “Stripe event → send email,” simpler tools may be faster. Talk to an automation expert if you want help choosing.
Once this is running, churn signals stop living in dashboards nobody checks. The workflow handles the repetitive outreach so you can focus on the conversations that actually save accounts.
Need Help Setting This Up?
Our automation experts can build and customize this workflow for your specific needs. Free 15-minute consultation—no commitment required.