---
title: "SMTP | DreamFactory Docs"
source: "https://docs.dreamfactory.com/api-generation-and-connections/api-types/email/smtp"
canonical_url: "https://docs.dreamfactory.com/api-generation-and-connections/api-types/email/smtp"
converted_at: "2026-04-05T14:00:15.822Z"
format: "markdown"
converted_by: "html-to-md-ai"
---
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[​](#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[​](#prerequisites)

You need access to an SMTP server:

ProviderSMTP ServerPortSecurityGmailsmtp.gmail.com587TLSMicrosoft 365smtp.office365.com587TLSAmazon SESemail-smtp.`{region}`.amazonaws.com587TLSYahoosmtp.mail.yahoo.com587TLSSelf-hostedYour server25/465/587Varies

Gmail/Google WorkspaceGmail 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](https://myaccount.google.com/apppasswords)

---

## Creating an SMTP Email Service[​](#creating-an-smtp-email-service)

### Step 1: Navigate to API Generation[​](#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[​](#step-2-create-new-service)

Click the plus button and select **SMTP Email Service**.

### Step 3: Configure Service Details[​](#step-3-configure-service-details)

FieldDescriptionExampleNameService name (used in API URL)`email`LabelDisplay name`SMTP Email`DescriptionService description`Transactional email service`

### Step 4: Configure SMTP Settings[​](#step-4-configure-smtp-settings)

FieldRequiredDescriptionHostYesSMTP server hostnamePortYesSMTP port (25, 465, or 587)EncryptionNo`tls`, `ssl`, or noneUsernameYes*SMTP authentication usernamePasswordYes*SMTP authentication password

*Required for authenticated SMTP servers (most providers).

### Step 5: Configure Sender Defaults[​](#step-5-configure-sender-defaults)

FieldDescriptionDefault From NameSender name for emailsDefault From EmailSender email addressDefault Reply-To NameReply-to nameDefault Reply-To EmailReply-to email address

### Step 6: Save and Test[​](#step-6-save-and-test)

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

---

## Configuration Options[​](#configuration-options)

### Required Settings[​](#required-settings)

FieldTypeDescription`host`stringSMTP server hostname

### Optional Settings[​](#optional-settings)

FieldTypeDefaultDescription`port`integer`587`SMTP port`encryption`string-Encryption type (`tls` or `ssl`). Leave empty to disable.`username`string-SMTP authentication username`password`string-SMTP authentication password

### Provider-Specific Configuration[​](#provider-specific-configuration)

**Gmail:**

```
Host: smtp.gmail.comPort: 587Encryption: tlsUsername: [email protected]Password: your_app_password
```

**Microsoft 365:**

```
Host: smtp.office365.comPort: 587Encryption: tlsUsername: [email protected]Password: your_password
```

**Amazon SES:**

```
Host: email-smtp.us-east-1.amazonaws.comPort: 587Encryption: tlsUsername: SMTP_USERNAME (from SES console)Password: SMTP_PASSWORD (from SES console)
```

---

## API Endpoints[​](#api-endpoints)

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

---

## API Examples[​](#api-examples)

### Send a Basic Email[​](#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": "[email protected]", "name": "John Doe"}    ],    "subject": "Test Email",    "body_text": "This is a test email sent via DreamFactory."  }'
```

**Response:**

```
{  "count": 1}
```

### Send HTML Email[​](#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": "[email protected]", "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[​](#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": "[email protected]", "name": "User One"},      {"email": "[email protected]", "name": "User Two"}    ],    "cc": [      {"email": "[email protected]", "name": "Manager"}    ],    "bcc": [      {"email": "[email protected]"}    ],    "subject": "Team Update",    "body_text": "Here is the weekly team update..."  }'
```

### Send with Custom Sender[​](#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": "[email protected]"}    ],    "from_name": "Support Team",    "from_email": "[email protected]",    "reply_to_email": "[email protected]",    "subject": "Re: Your Support Request",    "body_text": "Thank you for contacting support..."  }'
```

### Send with Attachments[​](#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": "[email protected]"}    ],    "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[​](#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": "[email protected]"}    ],    "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[​](#smtp-port-and-encryption)

PortEncryptionDescription25NoneUnencrypted (not recommended)465SSLImplicit TLS (legacy)587TLSSTARTTLS (recommended)

### Encryption Types[​](#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[​](#authentication-methods)

### Username/Password[​](#usernamepassword)

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

### OAuth2 (Microsoft 365)[​](#oauth2-microsoft-365)

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

### AWS SES Credentials[​](#aws-ses-credentials)

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

---

## Common Errors[​](#common-errors)

Error CodeMessageCauseSolution400Bad RequestInvalid email formatCheck recipient addresses401UnauthorizedMissing API keyAdd DreamFactory API key500Authentication failedWrong SMTP credentialsVerify username/password500Connection refusedWrong host/portCheck SMTP server settings500Connection timed outFirewall blockingAllow outbound SMTP ports500Certificate errorTLS issueCheck encryption setting

### Troubleshooting[​](#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[​](#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[​](#rate-limits)

SMTP providers enforce sending limits:

ProviderLimitGmail (free)500/dayGoogle Workspace2,000/dayMicrosoft 36510,000/dayAmazon SESBased on account

### Handling Rate Limits[​](#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[​](#security-best-practices)

### Credential Security[​](#credential-security)

- Store SMTP passwords in DreamFactory, never in client code

- Use app-specific passwords when available

- Rotate credentials periodically

### Sender Authentication[​](#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[​](#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[​](#php-mail-configuration)

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

```
MAIL_DRIVER=smtpMAIL_HOST=smtp.example.comMAIL_PORT=587MAIL_USERNAME=your_usernameMAIL_PASSWORD=your_passwordMAIL_ENCRYPTION=tls[email protected]MAIL_FROM_NAME=DreamFactory
```

---

## Next Steps[​](#next-steps)

- **[Email Overview](/api-generation-and-connections/api-types/email/email-overview)**: Compare email service options

- **[Role-Based Access Control](/api-security/rbac)**: Restrict email permissions

- **[Rate Limiting](/api-security/rate-limiting)**: Prevent email abuse