SMTP Configuration Guide
Configure SMTP settings to enable email delivery for password resets, email verification, and other notifications in your Keycloak realms.
Overview
Skycloak supports any SMTP-compatible email service. This guide covers configuration for popular providers including:
- Microsoft 365 / Office 365
- Azure Communication Services
- Google Workspace (formerly G Suite)
- Gmail
- SendGrid
- Amazon SES
- Mailgun
Common SMTP Settings
Before configuring your provider, understand these common settings:
- SMTP Host: The server address for sending emails
- SMTP Port: Usually 587 (TLS) or 465 (SSL)
- Username: Your SMTP authentication username
- Password: Your SMTP authentication password or app-specific password
- From Email: The email address that appears as the sender
- From Name: The display name for the sender
- SSL/TLS: Security protocol settings
Provider Configuration Guides
Microsoft 365 / Office 365
Microsoft offers multiple SMTP options. Choose based on your needs:
Option 1: Authenticated SMTP (Recommended for User Mailboxes)
Best for: Applications sending email as specific users with Microsoft 365 licenses.
Settings:
-
SMTP Host:
smtp.office365.com -
Port:
587 -
Username: Your full email address (e.g.,
[email protected]) - Password: Your Microsoft 365 password or app-specific password
- Enable TLS: Yes
- Enable SSL: No
Setup Steps:
- Ensure SMTP AUTH is enabled in Microsoft 365 admin center
- For accounts with MFA, create an app password:
- Sign in to https://mysignins.microsoft.com/security-info
- Add method → App password
- Name it (e.g., “Keycloak SMTP”)
- Copy the generated password
- Use your email address as username and the app password as password
- Verify the mailbox has a valid Microsoft 365 license
Requirements:
- Microsoft 365 license for the sending account
- SMTP AUTH must be enabled (check Exchange admin center)
- No IP restrictions on the account
Option 2: SMTP Relay (Best for Applications)
Best for: Applications and devices that need to send email without per-user licenses. Ideal for Keycloak deployments.
Settings:
-
SMTP Host:
smtp.office365.com -
Port:
587 - Username: Leave empty (no authentication)
- Password: Leave empty (no authentication)
- Enable TLS: Yes
- Enable SSL: No
- From Email: Any address in your verified domains
Setup Steps:
-
Create a Connector in Exchange Admin Center:
- Sign in to Exchange admin center
- Go to Mail flow → Connectors
- Click “+ Add a connector”
- From: “Your organization’s email server”
- To: “Microsoft 365”
- Name it (e.g., “Keycloak SMTP Relay”)
-
Configure Authentication:
- Choose “By verifying that the IP address…”
- Add your Keycloak server’s static IP address
- This IP must be static and dedicated
-
Set Security Restrictions:
- Reject messages if not encrypted: Yes (recommended)
- Reject messages if not from your domains: Yes
-
Update SPF Records: Add your server IP to SPF:
v=spf1 ip4:YOUR_SERVER_IP include:spf.protection.outlook.com -all -
Test the Connector:
- Use the built-in test in Exchange admin center
- Send a test email from Keycloak
Advantages:
- No per-user licensing required
- Higher sending limits (10,000 messages/day)
- Simpler credential management
- Better for automated/system emails
Limitations:
- Requires static IP address
- Can only send from verified domains
- Cannot send to external recipients unless they’re in your directory
Option 3: Direct Send (Simple but Limited)
Best for: Internal notifications only (cannot send to external recipients).
Settings:
-
SMTP Host: Your MX endpoint (e.g.,
yourdomain-com.mail.protection.outlook.com) -
Port:
25 - Username: None
- Password: None
- Enable TLS: Optional
- Enable SSL: No
Note: This method is very limited and not recommended for Keycloak.
Choosing the Right Method
| Method | Best For | Licensing | External Recipients | Setup Complexity |
|---|---|---|---|---|
| Authenticated SMTP | User-specific emails | Required | Yes | Easy |
| SMTP Relay | Applications/Keycloak | Not required | Yes* | Medium |
| Direct Send | Internal only | Not required | No | Easy |
*With proper connector configuration
Troubleshooting Microsoft 365 SMTP:
- Authentication failures: Check if SMTP AUTH is disabled organization-wide
- “5.7.57 Client not authenticated”: SMTP AUTH may be disabled for the user
- “5.7.60 SMTP client does not have permissions”: Check connector IP configuration
- Rate limiting: Microsoft 365 has a 30 messages/minute limit for authenticated SMTP
- SPF failures: Ensure your server IP is in the SPF record
PowerShell Commands for Admins:
# Check if SMTP AUTH is enabled globally
Get-TransportConfig | Format-List SmtpClientAuthenticationDisabled
# Enable SMTP AUTH globally (if disabled)
Set-TransportConfig -SmtpClientAuthenticationDisabled $false
# Check SMTP AUTH for specific user
Get-CASMailbox -Identity [email protected] | Format-List SmtpClientAuthenticationDisabled
# Enable SMTP AUTH for specific user
Set-CASMailbox -Identity [email protected] -SmtpClientAuthenticationDisabled $falseAzure Communication Services
Azure Communication Services provides reliable email delivery with built-in analytics. Important: SMTP authentication requires creating an Entra (Azure AD) application.
Settings:
-
SMTP Host:
smtp.azurecomm.net -
Port:
587 -
Username:
<ACS_Resource_Name>.<Application_ID>.<Tenant_ID> - Password: Your Entra app client secret (not the ACS access key)
- Enable TLS: Yes
- Enable SSL: No
Setup Steps:
Step 1: Create Azure Communication Services Resource
- Sign in to Azure Portal
- Create a new Azure Communication Services resource
- Note the resource name (e.g.,
myacsresource) - you’ll need this for the username
Step 2: Configure Email Domain
- In your ACS resource, go to Email → Domains
- Click “Connect domain” or “Add domain”
- Choose between:
-
Azure managed domain: Quick setup with
*.azurecomm.netaddress - Custom domain: Use your own domain (requires DNS verification)
-
Azure managed domain: Quick setup with
- For custom domains:
- Add the provided TXT record to verify ownership
- Configure SPF and DKIM records as shown
- Wait for verification (can take up to 30 minutes)
Step 3: Register an Entra Application
- Go to Microsoft Entra ID (formerly Azure Active Directory)
- Navigate to App registrations → New registration
- Configure the application:
- Name: e.g., “ACS SMTP Authentication”
- Supported account types: “Accounts in this organizational directory only”
- Redirect URI: Leave empty (not needed for SMTP)
- Click Register
- On the overview page, note:
-
Application (client) ID: e.g.,
12345678-1234-1234-1234-123456789012 -
Directory (tenant) ID: e.g.,
87654321-4321-4321-4321-210987654321
-
Application (client) ID: e.g.,
Step 4: Create Client Secret
- In your Entra app, go to Certificates & secrets
- Click New client secret
- Add a description (e.g., “SMTP Authentication”)
- Choose expiry (recommendation: 12 or 24 months)
- Click Add
- Important: Copy the secret value immediately - it won’t be shown again!
Step 5: Grant API Permissions
- In your Entra app, go to API permissions
- Click Add a permission
- Select APIs my organization uses
- Search for “Azure Communication Services”
- Select Azure Communication Services
- Choose Delegated permissions
- Select user_impersonation
- Click Add permissions
- If you’re an admin, click Grant admin consent (otherwise ask your admin)
Step 6: Build Your SMTP Credentials
Username Format: <ACS_Resource_Name>.<Application_ID>.<Tenant_ID>
Example:
- ACS Resource Name:
myacsresource - Application ID:
12345678-1234-1234-1234-123456789012 - Tenant ID:
87654321-4321-4321-4321-210987654321 -
Username:
myacsresource.12345678-1234-1234-1234-123456789012.87654321-4321-4321-4321-210987654321
Password: The client secret value from Step 4
Step 7: Configure in Skycloak
- Go to your realm’s SMTP settings
- Enter:
-
SMTP Host:
smtp.azurecomm.net -
Port:
587 - Username: The formatted username from Step 6
- Password: The client secret from Step 4
- From Email: Must match your verified domain
- Enable StartTLS: Yes
-
SMTP Host:
- Save and test the configuration
Troubleshooting Azure Communication Services SMTP:
-
“5.7.3 Authentication unsuccessful”:
- Verify the username format is exactly
<resource>.<appId>.<tenantId> - Ensure no extra spaces or characters
- Resource name is case-sensitive
- Verify the username format is exactly
-
“Client was not authenticated”:
- Check that API permissions were granted
- Verify admin consent was provided if required
- Ensure the client secret hasn’t expired
-
“Invalid client secret provided”:
- You may have copied the secret ID instead of the value
- Generate a new client secret if needed
-
“Sender address not verified”:
- The From email must match a verified domain
- Check domain verification status in ACS Email settings
-
SPF/DKIM failures:
- Verify DNS records match exactly as shown in Azure
- Allow 24-48 hours for DNS propagation
Important Notes:
- The Entra app username format is different from the old endpoint/access key method
- Client secrets expire - set a reminder to rotate before expiry
- Each Entra app can have multiple client secrets for rotation
- Monitor usage in Azure Portal under ACS → Metrics
Outlook.com (Personal Accounts)
For personal Microsoft accounts (Outlook.com, Hotmail, Live.com).
Settings:
-
SMTP Host:
smtp-mail.outlook.com -
Port:
587 - Username: Your full email address
- Password: Your password or app-specific password
- Enable TLS: Yes
- Enable SSL: No
Setup Steps:
- If you have 2FA enabled, create an app password:
- Go to https://account.microsoft.com/security
- Select “Advanced security options”
- Under “App passwords”, create a new password
- Use your email address as username
- Use the app password (if 2FA) or regular password
Note: This is for personal accounts only. For business accounts, use Microsoft 365/Office 365 settings above.
Google Workspace
For organizations using Google Workspace for business email.
Settings:
-
SMTP Host:
smtp.gmail.com -
Port:
587 -
Username: Your full Google Workspace email (e.g.,
[email protected]) - Password: App-specific password (see setup steps)
- Enable TLS: Yes
- Enable SSL: No
Setup Steps:
- Enable 2-factor authentication for your Google Workspace account
- Go to Google Account Security
- Under “2-Step Verification”, select “App passwords”
- Generate a new app password for “Mail”
- Use this 16-character password in SMTP configuration
Note: Less secure app access is deprecated. Always use app-specific passwords.
Gmail (Personal Accounts)
For development or testing with personal Gmail accounts.
Settings:
-
SMTP Host:
smtp.gmail.com -
Port:
587 - Username: Your Gmail address
- Password: App-specific password (required)
- Enable TLS: Yes
- Enable SSL: No
Setup Steps:
- Enable 2-factor authentication on your Gmail account
- Visit Google App Passwords
- Select “Mail” and your device
- Copy the generated 16-character password
- Use this password in your SMTP configuration
Important: Gmail has sending limits (500 emails/day for personal accounts).
SendGrid
A popular transactional email service with high deliverability.
Settings:
-
SMTP Host:
smtp.sendgrid.net -
Port:
587 -
Username:
apikey(literal string) - Password: Your SendGrid API key
- Enable TLS: Yes
- Enable SSL: No
Setup Steps:
- Create a SendGrid account and verify your email
- Navigate to Settings > API Keys
- Create a new API key with “Mail Send” permissions
- Use “apikey” as username and the API key as password
- Verify your sender domain for better deliverability
Amazon SES
Amazon’s scalable email service, ideal for AWS users.
Settings:
-
SMTP Host:
email-smtp.[region].amazonaws.com(e.g.,email-smtp.us-east-1.amazonaws.com) -
Port:
587 - Username: Your SMTP username (not your AWS access key)
- Password: Your SMTP password (not your AWS secret key)
- Enable TLS: Yes
- Enable SSL: No
Setup Steps:
- Enable SES in your AWS region
- Verify your domain or email address
- Navigate to SES > SMTP Settings
- Create SMTP credentials (creates an IAM user)
- Use the generated SMTP username and password
- Request production access to remove sandbox limitations
Mailgun
Developer-friendly email service with powerful APIs.
Settings:
-
SMTP Host:
smtp.mailgun.org(US) orsmtp.eu.mailgun.org(EU) -
Port:
587 - Username: Your Mailgun SMTP username (usually your domain)
- Password: Your Mailgun SMTP password
- Enable TLS: Yes
- Enable SSL: No
Setup Steps:
- Sign up for Mailgun and add your domain
- Verify your domain with DNS records
- Navigate to Sending > Domain settings > SMTP credentials
- Create SMTP credentials for your domain
- Use the provided username and password
Security Best Practices
- Use App-Specific Passwords: Never use your main account password
- Enable TLS/SSL: Always use encrypted connections
- Verify Sender Domains: Improves deliverability and prevents spoofing
- Monitor Sending Limits: Each provider has different limits
- Use Dedicated IPs: For high-volume sending (available with some providers)
- Regular Key Rotation: Update API keys and passwords periodically
Testing Your Configuration
After configuring SMTP:
- Save your SMTP settings in Skycloak
- Use the “Test SMTP” button to send a test email
- Check your inbox and spam folder
- Review any error messages in the UI
Troubleshooting
Common Issues
Authentication Failed
- Verify username and password are correct
- Check if app-specific password is required
- Ensure account has SMTP permissions enabled
Connection Timeout
- Verify SMTP host and port are correct
- Check firewall rules allow outbound SMTP
- Try alternate ports (587, 465, 25)
Emails Going to Spam
- Configure SPF, DKIM, and DMARC records
- Use a verified sender domain
- Avoid spam trigger words in content
Rate Limiting
- Check provider’s sending limits
- Implement email queuing for bulk sends
- Consider upgrading your plan
Provider Comparison
| Provider | Free Tier | Deliverability | Setup Complexity | Best For |
|---|---|---|---|---|
| Gmail | 500/day | Good | Easy | Development |
| Google Workspace | Varies | Excellent | Easy | Business email |
| Microsoft 365 (Auth) | Varies by plan | Excellent | Easy | Business with M365 |
| Microsoft 365 (Relay) | No extra cost | Excellent | Medium | Applications/Keycloak |
| SendGrid | 100/day | Excellent | Medium | Production apps |
| Amazon SES | 62,000/month* | Excellent | Complex | AWS users |
| Azure Comm Services | Pay-as-you-go | Excellent | Medium | Azure users |
| Mailgun | 1,000/month | Excellent | Medium | Developers |
*After leaving sandbox mode
Next Steps
- Configure email templates for your brand
- Set up custom domain for better deliverability
- Monitor insights for email and user analytics