Docs / mailbridge / Providers

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.

✓ Templates ✓ Bulk — 1,000/call ✓ Tracking Requires mailbridge[sendgrid]

Configuration

python
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

api_key
Required. SendGrid API key. Get one at app.sendgrid.com/settings/api_keys. Must start with SG.
from_email
Optional. Default sender address. Can be overridden per-send call.

Template IDs

SendGrid Dynamic Template IDs start with d-. Create templates in the SendGrid dashboard under Email API → Dynamic Templates.

python
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

python
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.

SES

Amazon SES

✓ Templates ✓ Bulk — auto-batched to 50/call ✓ Tracking via config sets Requires mailbridge[ses]

Configuration

python
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:

python
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:

python
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

aws_access_key_id
Optional if using IAM role. AWS access key ID.
aws_secret_access_key
Optional if using IAM role. AWS secret access key.
region_name
Required. AWS region where SES is configured (e.g. us-east-1, eu-west-1).
from_email
Required. Sender address — must be verified in the SES console.
configuration_set_name
Optional. SES configuration set name for open/click tracking and bounce monitoring.

Templates

SES templates are created in the AWS console or via CLI. Template IDs are the names you assign — not auto-generated strings.

bash
# 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}}!"
  }
}'
python
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.

PM

Postmark

✓ Templates ✓ Bulk — 500/call ✓ Open & click tracking ✓ No extra install needed

Configuration

python
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:

python
# 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

server_token
Required. Server API token from Postmark server settings.
from_email
Required. Sender address — must be a verified sender signature or domain.
message_stream
Optional. Postmark message stream ID. Default: outbound. Use broadcasts for marketing email.

Open & click tracking

python
response = mailer.send(
    to='user@example.com',
    subject='Tracked Email',
    body='

Click here

', track_opens=True, track_links='HtmlAndText' # 'None' | 'HtmlAndText' | 'HtmlOnly' | 'TextOnly' )
✓ Templates ✓ Bulk — Native ✓ Tracking ✓ No extra install needed

Configuration

python
mailer = MailBridge(
    provider='mailgun',
    api_key='key-xxxxx',
    domain='mg.yourdomain.com',          # Required — your Mailgun sending domain
    from_email='noreply@yourdomain.com'
)

Options

api_key
Required. Mailgun API key — starts with key-.
domain
Required. Your Mailgun sending domain (e.g. mg.yourdomain.com). Configure and verify it in the Mailgun dashboard.
from_email
Optional. Default sender address.
python
# 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'] )
BR

Brevo

formerly Sendinblue
✓ Templates ✓ Bulk — Native ✓ Tracking ✓ No extra install needed

Configuration

python
mailer = MailBridge(
    provider='brevo',
    api_key='xkeysib-xxxxx',             # Brevo API key — starts with 'xkeysib-'
    from_email='noreply@yourdomain.com'
)

Options

api_key
Required. Brevo API key — starts with xkeysib-. Get it at app.brevo.com/settings/keys/api.
from_email
Optional. Default sender address.

Brevo template IDs are integers, not strings. Pass template_id=123 not template_id='123'.

python
# 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

— No templates — No bulk API ✓ Universal compatibility ✓ No extra install needed

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

python
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.

python
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:

python
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:

python
mailer = MailBridge(
    provider='smtp',
    host='localhost',
    port=1025,                      # Mailpit default port
    from_email='test@localhost'
    # No username/password needed
)

Options

host
Required. SMTP server hostname.
port
Required. SMTP port. Common values: 587 (TLS), 465 (SSL), 25 (standard, often blocked).
username
Optional. SMTP username. Not needed for local servers.
password
Optional. SMTP password. For Gmail, use an App Password — not your Google account password.
use_tls
Optional. Use STARTTLS. Set to True for port 587. Mutually exclusive with use_ssl.
use_ssl
Optional. Use SSL. Set to True for port 465. Mutually exclusive with use_tls.
from_email
Optional. Default sender address.

Port reference

PortEncryptionOptionNotes
587STARTTLSuse_tls=TrueRecommended
465SSL/TLSuse_ssl=TrueLegacy SSL
25None / STARTTLSOften blocked by ISPs
2525STARTTLSuse_tls=TrueAlternative to 587
All providers covered

Ready to go? Check the Quick Start for common patterns — templates, attachments, bulk sending, and FastAPI integration.