Skip to main content

Email Services Overview

DreamFactory provides email services for sending transactional emails through your APIs. Connect SMTP servers or cloud email providers to enable email functionality in your applications without exposing credentials to clients.


Supported Email Services

ServiceTypeUse CaseDocumentation
SMTPProtocolAny SMTP serverSMTP Guide
MailgunAPITransactional emailCommercial license
SendGridAPITransactional emailCommercial license
Amazon SESAPIAWS email serviceCommercial license
MandrillAPIMailchimp transactionalCommercial license
SparkPostAPIHigh-volume emailCommercial license
LocalFileDevelopment/testingBuilt-in
Licensing

SMTP is included in DreamFactory OSS. Cloud email provider connectors (Mailgun, SendGrid, SES, etc.) require a commercial license.


Email Use Cases

Transactional Email

Send automated emails triggered by application events:

  • User registration: Welcome emails, email verification
  • Password reset: Secure reset links
  • Order confirmations: E-commerce receipts
  • Notifications: Alerts, reminders, updates
  • Reports: Scheduled report delivery

API-Driven Email

Send emails directly through the DreamFactory API:

curl -X POST "https://example.com/api/v2/email" \
-H "X-DreamFactory-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": [{"email": "user@example.com", "name": "John Doe"}],
"subject": "Your Order Confirmation",
"body_html": "<h1>Thank you for your order!</h1>",
"body_text": "Thank you for your order!"
}'

Choosing an Email Service

SMTP vs API Providers

FactorSMTPAPI Providers
Setup complexityMediumSimple
DeliverabilityDepends on server reputationOptimized
Rate limitsServer-dependentPlan-dependent
AnalyticsBasic (logs)Detailed (opens, clicks)
CostServer hostingPer-email pricing
ReliabilitySelf-managedProvider SLA

Provider Comparison

ProviderBest ForPricing Model
SMTP (self-hosted)Full control, existing infrastructureServer costs only
Amazon SESAWS infrastructure, high volume, low cost$0.10/1,000 emails
SendGridDeveloper-friendly, good deliverabilityFree tier + paid plans
MailgunDevelopers, API-first approachPay-as-you-go
SparkPostEnterprise, high-volume sendersEnterprise pricing

Recommendations

ScenarioRecommended Service
Development/testingLocal or SMTP (Mailtrap)
Small applicationsSendGrid free tier
AWS infrastructureAmazon SES
High deliverability needsMailgun, SendGrid
Enterprise/high-volumeSparkPost, Amazon SES

Email Service Architecture

┌─────────────────┐     ┌──────────────────┐     ┌─────────────────┐
│ API Client │────▶│ DreamFactory │────▶│ Email Service │
│ (App/Script) │◀────│ (Email API) │ │ (SMTP/API) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
HTTP Request Send Email Deliver Email
+ API Key via configured to inbox
service

Key Benefits

  1. Credential protection: SMTP/API credentials never exposed to clients
  2. Unified interface: Same API regardless of backend provider
  3. Access control: Role-based email permissions
  4. Audit logging: Track all sent emails
  5. Rate limiting: Prevent email abuse

Common Configuration Options

All email services share these configuration fields:

FieldTypeDescription
namestringService name (used in API URL)
labelstringDisplay name in admin console
descriptionstringService description
from_namestringDefault sender name
from_emailstringDefault sender email address
reply_to_namestringDefault reply-to name
reply_to_emailstringDefault reply-to address

API Endpoints

MethodEndpointDescription
POST/api/v2/{service}Send an email
GET/api/v2/{service}Get service configuration (admin only)

Email Request Format

Basic Email

{
"to": [
{"email": "recipient@example.com", "name": "Recipient Name"}
],
"subject": "Email Subject",
"body_text": "Plain text email body",
"body_html": "<h1>HTML email body</h1>"
}

Full Email Options

{
"to": [
{"email": "recipient@example.com", "name": "Recipient"}
],
"cc": [
{"email": "cc@example.com", "name": "CC Recipient"}
],
"bcc": [
{"email": "bcc@example.com", "name": "BCC Recipient"}
],
"from_name": "Sender Name",
"from_email": "sender@example.com",
"reply_to_name": "Reply Handler",
"reply_to_email": "reply@example.com",
"subject": "Email Subject",
"body_text": "Plain text version",
"body_html": "<html><body><h1>HTML version</h1></body></html>",
"attachments": [
{
"name": "document.pdf",
"content": "base64_encoded_content",
"content_type": "application/pdf"
}
]
}

Email Fields

FieldTypeRequiredDescription
toarrayYesList of recipient objects
subjectstringYesEmail subject line
body_textstringNo*Plain text email body
body_htmlstringNo*HTML email body
from_namestringNoOverride default sender name
from_emailstringNoOverride default sender email
ccarrayNoCarbon copy recipients
bccarrayNoBlind carbon copy recipients
reply_to_namestringNoReply-to name
reply_to_emailstringNoReply-to email
attachmentsarrayNoFile attachments

*At least one of body_text or body_html is required.


Email Templates

For consistent branding, use templated emails:

Simple Variable Replacement

Use placeholders in your email body:

{
"to": [{"email": "user@example.com"}],
"subject": "Welcome, {first_name}!",
"body_html": "<h1>Welcome to {company_name}</h1><p>Hello {first_name},</p>",
"template_data": {
"first_name": "John",
"company_name": "Acme Corp"
}
}

Provider Templates

Some providers (SendGrid, Mailgun) support server-side templates:

{
"to": [{"email": "user@example.com"}],
"template_id": "welcome-email-v2",
"template_data": {
"first_name": "John"
}
}

Security Best Practices

Sender Authentication

Configure SPF, DKIM, and DMARC for your sending domain:

  1. SPF: Authorize sending servers
  2. DKIM: Sign emails cryptographically
  3. DMARC: Policy for failed authentication

Rate Limiting

Apply rate limits to prevent abuse:

User TypeRecommended Limit
Regular users10 emails/hour
Power users100 emails/hour
Service accountsBased on needs

Role-Based Access

Restrict email sending by role:

  1. Navigate to Roles in admin console
  2. Configure email service access
  3. Limit recipients or templates if needed

Common Errors

Error CodeMessageCauseSolution
400Bad RequestInvalid email formatCheck recipient addresses
401UnauthorizedMissing API keyAdd API key header
403ForbiddenEmail sending not permittedCheck role permissions
422Unprocessable EntityMissing required fieldsInclude to, subject, body
500Service ErrorEmail service failureCheck service configuration
503Service UnavailableSMTP/API unreachableCheck credentials and connectivity

Development and Testing

Local Email Service

The local email driver saves emails to files instead of sending:

MAIL_DRIVER=local

Emails are saved to storage/logs/ for inspection.

Email Testing Services

Use these services to test without sending real emails:

ServiceDescription
MailtrapFake SMTP server for testing
MailHogSelf-hosted email testing
MailcatcherLocal SMTP with web UI

Next Steps