Version: 1.1.0Documentation Index
Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
Use this file to discover all available pages before exploring further.
Last Updated: 2026-03-11 This guide documents how to configure email and SMS notification services for the Encore Health OS Platform.
Table of Contents
- Overview
- Email Service (Entra ID & Gmail)
- SMS Service (Twilio)
- Template Configuration
- Rate Limiting & Quotas
- Cost Optimization
- Error Handling
- Testing
- Troubleshooting
Overview
Encore Health OS uses external services for email and SMS delivery:- Email: Microsoft Entra ID (Graph API) or Gmail (Google Workspace) — org-level sending. Configure per organization in HR Settings and Settings → Integrations.
- SMS: Twilio (primary provider)
send-email-notification- Single notification deliverysend-pending-notifications- Batch processinghr-portal-invite,hr-reference-request,hr-send-communication,hr-test-email- HR recruitmentautomation-executor- Workflow send-email actions- Signature flows:
send-signature-request,send-signature-reminder,auto-signature-remindersuse the shared email-provider (Entra/Gmail) per organization.
Email Service (Entra ID & Gmail)
Org-level email supports two providers. Choose one per organization in HR → Settings → Email Provider (and optionally set a fallback).Microsoft Entra ID (recommended)
- Configure the Entra ID integration in Settings → Integrations → Microsoft Entra ID (tenant, app registration, admin consent with
Mail.Send). - Set the sender email in the same page (or in
pf_organizations.settings.entra_sender_email). - Set ENTRA_CLIENT_SECRET in Supabase secrets (client secret for the app registration).
- In HR → Settings → Email, select Microsoft Entra ID and optionally set From Email Address / From Name.
Gmail (Google Workspace)
- Google Cloud: Create a project, enable Gmail API, create a service account.
- Domain-wide delegation: In Google Workspace Admin, grant the service account domain-wide delegation for scope
https://www.googleapis.com/auth/gmail.send. - Supabase secret: Set the service account JSON as a secret:
- Per-organization sender: In Settings → Integrations → Google Workspace (Gmail), set Sender email address to the Gmail/Workspace user to impersonate (e.g.
recruiting@yourcompany.com). This is stored inpf_organizations.settings.gmail_sender_email. - In HR → Settings → Email, select Gmail (Google Workspace) and optionally set From Email Address / From Name.
GMAIL_SERVICE_ACCOUNT_JSON (full JSON key for the service account).
Edge functions: All email senders use supabase/functions/_shared/email-provider.ts; no separate provider-specific integration is required beyond Entra/Gmail configuration.
SMS Service (Twilio)
1. Create Twilio Account
- Go to Twilio
- Sign up for account
- Verify phone number
2. Get Credentials
Account SID:- Go to Console → Account → API Keys & Tokens
- Copy Account SID (starts with
AC)
- Same page as Account SID
- Click Show next to Auth Token
- Copy Auth Token
- Go to Phone Numbers → Manage → Active Numbers
- Purchase phone number (or use trial number)
- Copy phone number (format:
+1234567890)
3. Set Supabase Secrets
4. Configure Edge Function
Edge Function:send-sms-notification
Required Secrets:
TWILIO_ACCOUNT_SIDTWILIO_AUTH_TOKENTWILIO_PHONE_NUMBER
supabase/functions/send-sms-notification/index.ts
Template Configuration
Email Templates
Template Variables:- Use
{{variable_name}}syntax - Variables replaced at send time
- Case-sensitive
SMS Templates
Message Limits:- Single SMS: 160 characters
- Messages > 160 characters are truncated
- Use concise templates
Rate Limiting & Quotas
Email (Entra / Gmail) Limits
Microsoft Graph (Entra): Throttling and quotas apply per tenant; see Microsoft documentation. Gmail API: Quotas and sending limits apply per Google Cloud project and per user; see Google documentation.Twilio Limits
Trial Account:- Limited to verified phone numbers
- SMS only to verified numbers
- No daily/monthly limits
- Pay per SMS sent
- No explicit rate limit
- Throttling may occur at very high volumes
Platform Limits
Encore Health OS Rate Limiting (Planned):- Email: Max 100 emails/hour per organization
- SMS: Max 50 SMS/hour per organization
- Enforced in edge functions
Cost Optimization
Email Costs (Entra / Gmail)
Entra: Included with Microsoft 365 licensing; Graph API usage subject to tenant limits. Gmail: Subject to Google Workspace and Gmail API quotas; no per-message fee for typical org usage. Optimization Tips:- Batch notifications when possible
- Use
send-pending-notificationsfor batch processing - Monitor email volume per organization
- Consider email digests for non-urgent notifications
SMS Costs (Twilio)
Pricing:- US/Canada: ~$0.0075 per SMS
- International: Varies by country
- MMS: Higher cost
- Use SMS only for urgent notifications
- Prefer email for non-urgent communications
- Batch SMS when possible (future feature)
- Monitor SMS volume per organization
Cost Monitoring
Email providers (Entra/Gmail):- Monitor provider dashboards for delivery volume, throttling, and failures
- Configure provider-side alerts/notifications for quota and auth issues
- Console shows usage and costs
- Set up spending limits
Error Handling
Email Errors
Entra (Graph API): 4xx/5xx from Graph; check tenant, app permissions, and sender identity. Gmail API: 4xx/5xx from Gmail; check service account, domain-wide delegation, and sender email. Error Handling: The sharedemail-provider returns EmailSendResult with success and errorMessage; callers update notification status and log accordingly.
SMS Errors
Common Error Codes:400- Invalid phone number403- Account suspended or insufficient credits500- Twilio service error
Retry Logic
Current Implementation:- No automatic retries
- Failed notifications marked as
failedin database - Manual retry via
send-pending-notifications
- Automatic retry with exponential backoff
- Max 3 retries
- Alert on persistent failures
Testing
Test Email Delivery
Development:- Send to verified email addresses
- Check Supabase function logs and provider dashboards (Entra/Gmail) for delivery status
Test SMS Delivery
Development:- Use Twilio’s test credentials
- Send to verified phone numbers (trial)
- Check Twilio console for delivery status
Test Templates
Test Template Variables:Troubleshooting
Issue: Email Not Sending
Symptoms:- No email received
- Function returns success but no email
- Entra: Verify ENTRA_CLIENT_SECRET and org Entra config (tenant, app, sender email). Check Graph consent includes Mail.Send.
- Gmail: Verify GMAIL_SERVICE_ACCOUNT_JSON and org
gmail_sender_emailin Settings → Integrations → Gmail. Confirm domain-wide delegation for gmail.send. - Verify recipient email address is valid.
- Check spam folder.
- Review function logs in Supabase dashboard.
Issue: SMS Not Sending
Symptoms:- No SMS received
- Function returns error
- Check Twilio credentials are set correctly
- Verify phone number format:
+1234567890 - Check Twilio account has credits
- Verify phone number is verified (trial account)
- Check Twilio console for delivery status
- Review function logs in Supabase dashboard
Issue: Template Variables Not Replaced
Symptoms:- Email/SMS contains
{{variable}}literally
- Verify variables object includes all template variables
- Check variable names match exactly (case-sensitive)
- Verify template syntax:
{{variable_name}} - Check function logs for variable replacement
Issue: Rate Limit Exceeded
Symptoms:- 429 errors from email provider or Twilio
- Notifications fail
- Implement rate limiting in application
- Batch notifications when possible
- For Entra/Gmail, check tenant or Google project quotas
- Use
send-pending-notificationsfor batch processing - Add retry logic with backoff
Issue: High Costs
Symptoms:- Unexpected charges from Twilio (or cloud provider)
- Monitor usage in provider dashboards
- Implement rate limiting per organization
- Use email digests for non-urgent notifications
- Prefer email over SMS when possible
- Set spending limits in Twilio console
Best Practices
1. Email Best Practices
- Use verified domains (Entra: org mailbox; Gmail: Workspace domain)
- Set up SPF/DKIM/DMARC per your domain
- Monitor bounce rates and handle bounces
- Use templates for consistency
- Test templates before production use
- Monitor delivery via Supabase logs and provider dashboards (Graph / Gmail)
2. SMS Best Practices
- Use SMS only for urgent notifications
- Keep messages concise (< 160 characters)
- Include opt-out instructions (if required)
- Verify phone numbers before sending
- Monitor delivery rates in Twilio console
- Handle failed deliveries gracefully
3. Security
- Never log full email addresses or phone numbers
- Sanitize user input in templates
- Validate email/phone formats before sending
- Use HTTPS for all API calls
- Rotate API keys regularly
- Monitor for abuse (unusual sending patterns)
Related Documentation
- Edge Functions:
docs/integrations/EDGE_FUNCTIONS.md - Environment Variables:
docs/development/ENVIRONMENT_VARIABLES.md - Secrets Management:
docs/security/SECRETS_MANAGEMENT.md - Notifications:
specs/pf/specs/PF-10-notification-system.md
Document Owner: Platform Team
Review Frequency: Quarterly
Last Updated: 2025-01-07