valstorm-plugin-sendgrid — Hybrid SendGrid Transactional Email & Event Webhook Plugin (FI-473)
Hybrid (Python + Go) SendGrid integration for Open Valstorm, mounted at platform.sendgrid (VALSTORM_PLUGINS=sendgrid or *).
Provides transactional and bulk email delivery, {{variable}} template rendering, VFS file attachments, Email Activity Log search, and high-throughput Go worker processing for /v3/mail/send (email:sendgrid) and SendGrid Event Webhooks (sendgrid:webhook_event -> sendgrid_email sgem_).
🤖 Agent-Assisted Quick Setup (Let the Valstorm Agent Set It Up)
You only need your SendGrid API Key (SG....) and verified sender email address. Your Valstorm AI Agent can validate your API key against SendGrid, save the encrypted credentials in platform.credentials, configure your SendGrid Event Webhook URL (/v1/email-services/sendgrid/webhook/<ORG_ID>) for open/click/delivery tracking, and verify live connectivity.
1. Quick Human Prerequisite (60 Seconds in SendGrid)
- Log in to app.sendgrid.com.
- Go to Settings -> API Keys -> Create API Key (grant Mail Send and Email Activity access) and copy the
SG....key. - Ensure your sender domain or Single Sender Address is verified under Settings -> Sender Authentication.
2. Copy-Paste Prompt for Your Valstorm Agent
Drop this prompt into Valstorm Chat:
"Set up
valstorm-plugin-sendgridusing my SendGrid API Key<SG.YOUR_KEY>and default sender<[email protected]>(Sender Name:<Your Company>). Followplugins/valstorm-plugin-sendgrid/README.mdto save the encrypted credentials viaplatform.sendgrid.save_credentials(...), configure the SendGrid Event Webhook, and runsendgrid_verify_connection."
3. Agent Execution Runbook (Instructions for the AI Agent)
When a user asks you to set up valstorm-plugin-sendgrid, execute this sequence autonomously:
- Validate & Save Encrypted Credentials:
- Call
await platform.sendgrid.save_credentials(api_key=..., from_email=..., from_name=..., validate_live=True)(orPOST /v1/email-services/sendgrid/credentials).
- Configure Event Webhook (
processed,delivered,open,click,bounce,dropped):
- Call
await platform.sendgrid.configure_event_webhook(base_url="https://<YOUR_API_DOMAIN>")so SendGrid posts delivery and engagement events to/v1/email-services/sendgrid/webhook/<ORG_ID>.
- Verify Live Connection:
- Call
sendgrid_verify_connectionand report the verified sender identity and webhook status back to the user.
🛠️ End-to-End DIY Setup Guide (Manual)
Step 1: Verify Your Domain or Single Sender in SendGrid
- In app.sendgrid.com, navigate to Settings -> Sender Authentication.
- Authenticate your sending domain (SPF/DKIM DNS records) or verify a Single Sender email address.
Step 2: Create a SendGrid API Key
- Go to Settings -> API Keys -> Create API Key.
- Copy the
SG....key (shown once).
Step 3: Configure the SendGrid Event Webhook
- Navigate to Settings -> Mail Settings -> Event Settings -> Event Webhook.
- Set the HTTP Post URL to:
https://api.yourdomain.com/v1/email-services/sendgrid/webhook/<YOUR_ORG_ID>
- Check Processed, Delivered, Opened, Clicked, Bounced, Dropped, Spam Report, and Unsubscribed, then click Save.
Step 4: Save Encrypted Credentials in Open Valstorm
await platform.sendgrid.save_credentials(
api_key="SG.xxxxxxxxxxxxxxxxxxxx.yyyyyyyyyyyyyyyyyyyy",
from_email="[email protected]",
from_name="Valstorm Notifications",
)Running Tests (Python & Go)
# Run Python unit & route tests
cd apps/open-api
.venv/bin/pytest tests/test_plugin_sendgrid.py -v
# Run Go worker `/v3/mail/send` & Event Webhook race tests
cd ../../plugins/valstorm-plugin-sendgrid/go
go test -race -v ./...