Skip to main content

SMTP

SMTP (Simple Mail Transfer Protocol) is the standard protocol for sending emails. DreamFactory's SMTP connector allows you to send emails through any SMTP server, including Gmail, Microsoft 365, Amazon SES, or your own mail server.


Use Cases

  • Transactional emails: Order confirmations, password resets, notifications
  • User communications: Welcome emails, account updates
  • Automated reports: Scheduled email delivery
  • Integration: Connect existing SMTP infrastructure to your API

Prerequisites

You need access to an SMTP server:

ProviderSMTP ServerPortSecurity
Gmailsmtp.gmail.com587TLS
Microsoft 365smtp.office365.com587TLS
Amazon SESemail-smtp.{region}.amazonaws.com587TLS
Yahoosmtp.mail.yahoo.com587TLS
Self-hostedYour server25/465/587Varies
Gmail/Google Workspace

Gmail requires an "App Password" when 2-factor authentication is enabled. Regular passwords will not work. Create an App Password at https://myaccount.google.com/apppasswords


Creating an SMTP Email Service

Step 1: Navigate to API Generation

Log in to your DreamFactory instance and select API Generation & Connections. Set API Type to Email.

Step 2: Create New Service

Click the plus button and select SMTP Email Service.

Step 3: Configure Service Details

FieldDescriptionExample
NameService name (used in API URL)email
LabelDisplay nameSMTP Email
DescriptionService descriptionTransactional email service

Step 4: Configure SMTP Settings

FieldRequiredDescription
HostYesSMTP server hostname
PortYesSMTP port (25, 465, or 587)
EncryptionNotls, ssl, or none
UsernameYes*SMTP authentication username
PasswordYes*SMTP authentication password

*Required for authenticated SMTP servers (most providers).

Step 5: Configure Sender Defaults

FieldDescription
Default From NameSender name for emails
Default From EmailSender email address
Default Reply-To NameReply-to name
Default Reply-To EmailReply-to email address

Step 6: Save and Test

Save the service, then send a test email using the API Docs.


Configuration Options

Required Settings

FieldTypeDescription
hoststringSMTP server hostname

Optional Settings

FieldTypeDefaultDescription
portinteger587SMTP port
encryptionstring-Encryption type (tls or ssl). Leave empty to disable.
usernamestring-SMTP authentication username
passwordstring-SMTP authentication password

Provider-Specific Configuration

Gmail:

Host: smtp.gmail.com
Port: 587
Encryption: tls
Username: your_email@gmail.com
Password: your_app_password

Microsoft 365:

Host: smtp.office365.com
Port: 587
Encryption: tls
Username: your_email@domain.com
Password: your_password

Amazon SES:

Host: email-smtp.us-east-1.amazonaws.com
Port: 587
Encryption: tls
Username: SMTP_USERNAME (from SES console)
Password: SMTP_PASSWORD (from SES console)

API Endpoints

MethodEndpointDescription
POST/api/v2/{service}Send an email

API Examples

Send a Basic Email

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": "recipient@example.com", "name": "John Doe"}
],
"subject": "Test Email",
"body_text": "This is a test email sent via DreamFactory."
}'

Response:

{
"count": 1
}

Send HTML Email

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": "recipient@example.com", "name": "John Doe"}
],
"subject": "Your Order Confirmation",
"body_html": "<html><body><h1>Order Confirmed</h1><p>Thank you for your order #12345.</p></body></html>",
"body_text": "Order Confirmed\n\nThank you for your order #12345."
}'

Send to Multiple Recipients

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": "user1@example.com", "name": "User One"},
{"email": "user2@example.com", "name": "User Two"}
],
"cc": [
{"email": "manager@example.com", "name": "Manager"}
],
"bcc": [
{"email": "archive@example.com"}
],
"subject": "Team Update",
"body_text": "Here is the weekly team update..."
}'

Send with Custom Sender

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": "customer@example.com"}
],
"from_name": "Support Team",
"from_email": "support@mycompany.com",
"reply_to_email": "support@mycompany.com",
"subject": "Re: Your Support Request",
"body_text": "Thank you for contacting support..."
}'

Send with Attachments

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": "recipient@example.com"}
],
"subject": "Invoice Attached",
"body_text": "Please find your invoice attached.",
"attachments": [
{
"name": "invoice-2026-001.pdf",
"content": "JVBERi0xLjQKJeLjz9MKMSAwIG9i...",
"content_type": "application/pdf"
}
]
}'

The content field must be Base64-encoded. Encode a file:

base64 invoice.pdf | tr -d '\n'

Email Templates with Variables

Include dynamic content using placeholders:

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"}
],
"subject": "Welcome, {first_name}!",
"body_html": "<h1>Welcome to {company_name}</h1><p>Hello {first_name},</p><p>Your account is ready.</p>",
"body_text": "Welcome to {company_name}\n\nHello {first_name},\n\nYour account is ready.",
"template_data": {
"first_name": "John",
"company_name": "Acme Corp"
}
}'

SMTP Port and Encryption

PortEncryptionDescription
25NoneUnencrypted (not recommended)
465SSLImplicit TLS (legacy)
587TLSSTARTTLS (recommended)

Encryption Types

  • TLS (STARTTLS): Starts unencrypted, upgrades to encrypted. Use port 587.
  • SSL: Encrypted from the start. Use port 465.
  • None: Unencrypted. Only use for local development.

Authentication Methods

Username/Password

Most common method. Use your email credentials or app-specific password.

OAuth2 (Microsoft 365)

For Microsoft 365 with modern authentication, you may need to configure OAuth2 instead of basic authentication.

AWS SES Credentials

For Amazon SES, generate SMTP credentials in the SES console (different from IAM credentials).


Common Errors

Error CodeMessageCauseSolution
400Bad RequestInvalid email formatCheck recipient addresses
401UnauthorizedMissing API keyAdd DreamFactory API key
500Authentication failedWrong SMTP credentialsVerify username/password
500Connection refusedWrong host/portCheck SMTP server settings
500Connection timed outFirewall blockingAllow outbound SMTP ports
500Certificate errorTLS issueCheck encryption setting

Troubleshooting

Authentication Failed:

  1. Verify username and password are correct
  2. For Gmail: Use an App Password, not your regular password
  3. Check if account has 2FA enabled (requires app password)
  4. Verify the account allows SMTP access

Connection Refused:

  1. Verify the SMTP host is correct
  2. Check the port matches the encryption type
  3. Ensure firewall allows outbound connections on the port

TLS/SSL Errors:

  1. Match encryption setting with port (587 = TLS, 465 = SSL)
  2. Check server certificate validity
  3. Try tls instead of ssl or vice versa

Test SMTP Connection

From the command line:

# Test TLS connection (port 587)
openssl s_client -starttls smtp -connect smtp.gmail.com:587

# Test SSL connection (port 465)
openssl s_client -connect smtp.gmail.com:465

Rate Limits

SMTP providers enforce sending limits:

ProviderLimit
Gmail (free)500/day
Google Workspace2,000/day
Microsoft 36510,000/day
Amazon SESBased on account

Handling Rate Limits

  1. Monitor usage to stay within limits
  2. Queue emails for gradual sending
  3. Use dedicated email service for high volume

Security Best Practices

Credential Security

  • Store SMTP passwords in DreamFactory, never in client code
  • Use app-specific passwords when available
  • Rotate credentials periodically

Sender Authentication

Configure these DNS records for better deliverability:

  1. SPF: Authorize your SMTP server to send for your domain
  2. DKIM: Sign emails cryptographically
  3. DMARC: Policy for handling authentication failures

Access Control

Configure role-based access:

  1. Limit which roles can send email
  2. Restrict sender addresses if needed
  3. Apply rate limiting per role

PHP Mail Configuration

For DreamFactory installations using PHP's mail configuration, set these in .env:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.example.com
MAIL_PORT=587
MAIL_USERNAME=your_username
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=noreply@example.com
MAIL_FROM_NAME=DreamFactory

Next Steps