Providers
Complete configuration reference for all six supported providers — credentials, options, provider-specific features, and notes on limitations. Jump directly to the provider you need.
SendGrid
mailbridge[sendgrid]
Configuration
from mailbridge import MailBridge
mailer = MailBridge(
provider='sendgrid',
api_key='SG.xxxxx', # Required — starts with 'SG.'
from_email='noreply@yourdomain.com' # Optional default sender
)
Options
SG.Template IDs
SendGrid Dynamic Template IDs start with d-. Create templates in the SendGrid dashboard under Email API → Dynamic Templates.
mailer.send(
to='user@example.com',
subject='', body='',
template_id='d-1234567890abcdef', # starts with 'd-'
template_data={
'user_name': 'Alice Smith',
'activation_link': 'https://yourapp.com/activate/abc123'
}
)
Tracking & Tags
mailer.send(
to='user@example.com',
subject='Summer Campaign',
body='Special offer!
',
headers={'X-Campaign-ID': 'summer-2025'},
tags=['marketing', 'summer-campaign'] # For analytics in SendGrid dashboard
)
The free SendGrid tier allows 100 emails/day. For higher volume, a paid plan is required. send_bulk() uses the native personalizations API — up to 1,000 messages per API call.
Amazon SES
mailbridge[ses]
Configuration
mailer = MailBridge(
provider='ses',
aws_access_key_id='AKIAXXXX',
aws_secret_access_key='xxxxx',
region_name='us-east-1', # Your AWS region
from_email='verified@yourdomain.com' # Must be verified in SES
)
If running on EC2 or Lambda with an IAM role that has SES permissions, you don't need to pass credentials at all:
mailer = MailBridge(
provider='ses',
region_name='us-east-1',
from_email='verified@yourdomain.com'
# No credentials needed — boto3 picks up the IAM role automatically
)
Add a configuration set to enable open and click tracking:
mailer = MailBridge(
provider='ses',
aws_access_key_id='AKIAXXXX',
aws_secret_access_key='xxxxx',
region_name='us-east-1',
from_email='verified@yourdomain.com',
configuration_set_name='my-tracking-set' # Created in SES console
)
Options
us-east-1, eu-west-1).Templates
SES templates are created in the AWS console or via CLI. Template IDs are the names you assign — not auto-generated strings.
# Create template via AWS CLI
aws ses create-template --cli-input-json '{
"Template": {
"TemplateName": "WelcomeTemplate",
"SubjectPart": "Welcome {{firstName}}!",
"HtmlPart": "<h1>Hello {{firstName}}!</h1>",
"TextPart": "Hello {{firstName}}!"
}
}'
mailer.send(
to='user@example.com',
subject='', body='',
template_id='WelcomeTemplate', # The name you gave the template
template_data={
'firstName': 'Alice',
'activationUrl': 'https://yourapp.com/activate/abc123'
}
)
SES starts in sandbox mode — you can only send to verified email addresses. Request production access to send to any recipient.
Postmark
Configuration
mailer = MailBridge(
provider='postmark',
server_token='xxxxx-xxxxx-xxxxx',
from_email='verified@yourdomain.com' # Must be a verified sender signature
)
Postmark separates transactional email from marketing email using message streams:
# Transactional (default — welcome, password reset, receipts)
mailer = MailBridge(
provider='postmark',
server_token='xxxxx-xxxxx',
from_email='noreply@yourdomain.com',
message_stream='outbound' # default stream
)
# Broadcast (newsletters, campaigns)
mailer_broadcast = MailBridge(
provider='postmark',
server_token='xxxxx-xxxxx',
from_email='news@yourdomain.com',
message_stream='broadcasts'
)
Options
outbound. Use broadcasts for marketing email.Open & click tracking
response = mailer.send(
to='user@example.com',
subject='Tracked Email',
body='Click here
',
track_opens=True,
track_links='HtmlAndText' # 'None' | 'HtmlAndText' | 'HtmlOnly' | 'TextOnly'
)
Mailgun
Configuration
mailer = MailBridge(
provider='mailgun',
api_key='key-xxxxx',
domain='mg.yourdomain.com', # Required — your Mailgun sending domain
from_email='noreply@yourdomain.com'
)
Options
key-.mg.yourdomain.com). Configure and verify it in the Mailgun dashboard.# Template (use template name created in Mailgun dashboard)
mailer.send(
to='user@example.com',
subject='', body='',
template_id='welcome-template',
template_data={'name': 'Alice', 'activation_link': 'https://...'}
)
# With tracking tags
mailer.send(
to='user@example.com',
subject='Campaign',
body='Special offer!
',
tags=['marketing', 'campaign-2025']
)
Brevo
formerly SendinblueConfiguration
mailer = MailBridge(
provider='brevo',
api_key='xkeysib-xxxxx', # Brevo API key — starts with 'xkeysib-'
from_email='noreply@yourdomain.com'
)
Options
xkeysib-. Get it at app.brevo.com/settings/keys/api.Brevo template IDs are integers, not strings. Pass template_id=123 not template_id='123'.
# Template ID is an integer in Brevo
mailer.send(
to='user@example.com',
subject='', body='',
template_id=12, # integer — not a string
template_data={'name': 'Alice', 'company': 'Acme'}
)
SMTP
SMTP works with any email account or server — Gmail, Outlook, Yahoo, or a custom mail server. It's the simplest way to get started.
Common configurations
mailer = MailBridge(
provider='smtp',
host='smtp.gmail.com',
port=587,
username='you@gmail.com',
password='your-app-password', # App Password — NOT your Google login password
use_tls=True,
from_email='you@gmail.com'
)
Gmail requires a 16-character App Password. Enable 2FA on your Google account first, then generate one under Account → Security → App Passwords.
mailer = MailBridge(
provider='smtp',
host='smtp.office365.com',
port=587,
username='you@outlook.com',
password='your-password',
use_tls=True,
from_email='you@outlook.com'
)
Custom mail server using SSL on port 465:
mailer = MailBridge(
provider='smtp',
host='mail.yourdomain.com',
port=465,
username='noreply',
password='your-password',
use_ssl=True, # use_ssl for port 465 — NOT use_tls
from_email='noreply@yourdomain.com'
)
Local SMTP server (e.g. Mailpit or Mailhog for development) — no authentication needed:
mailer = MailBridge(
provider='smtp',
host='localhost',
port=1025, # Mailpit default port
from_email='test@localhost'
# No username/password needed
)
Options
587 (TLS), 465 (SSL), 25 (standard, often blocked).True for port 587. Mutually exclusive with use_ssl.True for port 465. Mutually exclusive with use_tls.Port reference
| Port | Encryption | Option | Notes |
|---|---|---|---|
587 | STARTTLS | use_tls=True | Recommended |
465 | SSL/TLS | use_ssl=True | Legacy SSL |
25 | None / STARTTLS | — | Often blocked by ISPs |
2525 | STARTTLS | use_tls=True | Alternative to 587 |
Ready to go? Check the Quick Start for common patterns — templates, attachments, bulk sending, and FastAPI integration.