SendGrid custom domain click tracking TLS proxy using YARP and .NET 9. Includes logging and health check monitoring for production use.
This application solves a critical limitation with SendGrid's click tracking feature: the lack of HTTPS/TLS support for custom domains. It provides a secure, production-ready proxy that enables HTTPS click tracking while maintaining full compatibility with SendGrid's service.
SendGrid's click tracking feature has several limitations:
- No HTTPS support: Click tracking links only work over HTTP, not secure HTTPS
- SendGrid domain only: By default, links use
sendgrid.netdomain - Custom domain limitations: While SendGrid allows custom domains, they don't provide TLS certificates for them
Modern web security standards and corporate networks often:
- Automatically redirect HTTP to HTTPS
- Block or warn about insecure HTTP connections
- Require all traffic to be encrypted
This means SendGrid's HTTP-only click tracking often fails in production environments.
SendGrid Click Tracking TLS Proxy acts as a secure intermediary:
- Receives requests to your custom domain over HTTPS
- Validates and processes the click tracking data
- Forwards requests to SendGrid's infrastructure
- Returns responses securely to the user
- 🔒 Full TLS/HTTPS support for custom domains
- 🔄 HTTP to HTTPS upgrade for legacy links
- 📊 Production-ready logging with structured output
- ❤️ Health check monitoring for proactive alerting
- ⚡ High performance using YARP (Yet Another Reverse Proxy)
- 🏢 Enterprise ready with .NET 9 foundation
User clicks link → Your Custom Domain (HTTPS) → Proxy → SendGrid → Target URL
The proxy seamlessly handles the TLS termination while preserving all SendGrid click tracking functionality.
SendGrid:ClickTrackingCustomDomain
- Must exactly match your SendGrid custom domain configuration
- Only requests matching this domain will be proxied to SendGrid
- Non-matching requests are logged as errors
SendGrid:ClickTrackingPathsToMatch
- Array of root paths that must match for forwarding to SendGrid
- Default paths are typically
["ls", "wf"]but may vary
{
"SendGrid": {
"ClickTrackingCustomDomain": "clickme.mydomain.com",
"ClickTrackingPathsToMatch": ["ls", "wf", "newpath"]
}
}With this configuration:
✅ These requests will be proxied:
https://clickme.mydomain.com/ls/click?upn=u001.abc123http://clickme.mydomain.com/wf/open?upn=u001.abc123(upgraded to HTTPS)https://clickme.mydomain.com/newpath/click?upn=u001.abc123
❌ These requests will NOT be proxied:
https://someother.mydomain.com/ls/click?upn=u001.abc123(wrong domain)https://clickme.mydomain.com/randompath/click?upn=u001.abc123(wrong path)https://sub.clickme.mydomain.com/ls/click?upn=u001.abc123(subdomain)
Health endpoint: https://[your-domain]/health/sendgrid
✅ Working: https://clickme.mydomain.com/health/sendgrid
❌ Not working: https://someother.com/health/sendgrid or https://clickme.mydomain.com/healthcheck/sendgrid
Deploy to Azure App Service, AWS App Runner, or similar platforms where TLS is managed at the platform level.
- TLS Handling: Managed by hosting platform
- Kestrel Config: Default HTTP configuration
- Backend Requests: HTTP to SendGrid (always)
Deploy directly to VMs or containers where you manage TLS certificates.
- TLS Handling: Configure Kestrel with your certificates
- Kestrel Config: HTTPS configuration required
- Backend Requests: HTTP to SendGrid (always)
Note: Backend requests to SendGrid are always HTTP because the custom domain host header won't match SendGrid's TLS certificate.
** THE BELOW NEEDS MORE CLARIFICATION **
** ALSO NEED TO WORK ON BUILD ARTIFACTS **
- Download the latest release from GitHub releases
- Extract and deploy to your App Service
- Configure custom domain and TLS certificate in Azure
- Update application settings with your SendGrid configuration
- Test health endpoint to verify deployment
-
Clone the repository:
git clone https://github.com/yourusername/SendGridClickTrackTLSProxy.git
-
Configure settings in
appsettings.json -
Build and run:
dotnet build dotnet run
- Health Checks: Monitor
/health/sendgridendpoint - Structured Logging: All requests and errors are logged with context
- Configuration Validation: Invalid domains/paths are clearly logged
- Performance Metrics: YARP provides built-in performance monitoring
This proxy is essential for organizations requiring secure, professional email communications with reliable click tracking.