Skip to main content

Send emails via Microsoft Exchange Server with HTML template support

Project description

Ex(change E)mailer 🐍

Enterprise-Grade Microsoft Exchange Email Client with HTML Template Support

PyPI Python Versions Build Status License

ExMailer is a robust Python library designed for robust interaction with Microsoft Exchange Servers (EWS). It solves the complexity of NTLM authentication and provides a flexible, HTML templating engine out of the box.

Features

  • Microsoft Exchange Integration: Seamless connection to Exchange servers using NTLM authentication
  • Rich Email Formatting: Professional HTML email templates with customizable variables
  • Attachment Support: Handle multiple file attachments with automatic MIME type detection
  • Flexible Configuration: Support for environment variables, JSON config files, or programmatic setup
  • CLI Interface: Command-line tool for quick email sending
  • Comprehensive Error Handling: Custom exceptions for different failure scenarios
  • Secure SSL/TLS: Proper certificate verification and secure connections
  • Logging Support: Verbose mode for debugging and troubleshooting

Installation

Requires Python 3.11+

pip install exmailer

Quick Start

Using Python API

from exmailer import ExchangeEmailer

with ExchangeEmailer() as emailer:
    emailer.send_email(
        subject="گزارش هفتگی",
        body="لطفاً گزارش پیوست شده را بررسی نمایید.",
        recipients=["manager@company.com"],
        template=TemplateType.PERSIAN,  # Uses built-in RTL template
        attachments="./report.pdf",
    )

    # Send a standard English/LTR email
    emailer.send_email(
        subject="Weekly Report",
        body="Please find attached.",
        recipients=["colleague@company.com"],
        template=TemplateType.DEFAULT
        attachments="./report.pdf",
    )

Custom Templates

You can register custom HTML layouts for newsletters or alerts:

from exmailer import ExchangeEmailer, register_custom_template

html_layout = """
<div style="border: 1px solid #ccc; padding: 20px;">
    <h1 style="color: navy;">Company Alert</h1>
    {body}
    <hr>
    <small>Confidential</small>
</div>
"""

register_custom_template("alert", html_layout)

with ExchangeEmailer() as emailer:
    emailer.send_email(
        subject="Server Down",
        body="<p>The main database is unreachable.</p>",
        recipients=["devops@company.com"],
        template="alert"  # Use the registered name
    )

Using CLI (Under Construction)

python -m exchange_emailer \
    --subject "Weekly Report" \
    --body "Report content here" \
    --to recipient@company.com \
    --attachments ./report.pdf

Configuration

ExMailer looks for exmailer.json or exmailer.yaml in your current directory or ~/.config/exmailer/.

Set environment variables .env:

EXCHANGE_DOMAIN="CORP"
EXCHANGE_USER="jdoe"
EXCHANGE_PASS="secret_password"
EXCHANGE_SERVER="mail.corp.com"
EXCHANGE_EMAIL_DOMAIN="corp.com"
EXCHANGE_AUTH_TYPE="NTLM" # or BASIC

Or use a JSON config file exmailer.json:

{
  "domain": "CORP",
  "username": "jdoe",
  "password": "secret_password",
  "server": "mail.corp.com",
  "email_domain": "corp.com",
  "auth_type": "NTLM",
  "save_copy": true
}

Requirements

  • Python 3.10+
  • Microsoft Exchange Server access
  • Valid domain credentials

Author

Sadegh Yazdani

License

GNU General Public License v3 (GPLv3)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

exmailer-1.0.0.tar.gz (135.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

exmailer-1.0.0-py3-none-any.whl (28.1 kB view details)

Uploaded Python 3

File details

Details for the file exmailer-1.0.0.tar.gz.

File metadata

  • Download URL: exmailer-1.0.0.tar.gz
  • Upload date:
  • Size: 135.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for exmailer-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d53ecd5d36ccb48c751beab695950f873bfe22b53c0a4b6ecd71b3d436a028fa
MD5 6c2ef7fa43f7478ae0892813810d6016
BLAKE2b-256 13ed5d62e43b975ce9ba22cc66b46f4a06327689be2bf4c70bb24e4aab5301df

See more details on using hashes here.

Provenance

The following attestation bundles were made for exmailer-1.0.0.tar.gz:

Publisher: pypi_publish.yml on aerosadegh/exmailer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exmailer-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: exmailer-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 28.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for exmailer-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6f1492a40ea654714dfe51e2a7eda6d765f003aac7423a977f8c500e9500a91f
MD5 fbc885a707e4294e318a2fe7b9997bda
BLAKE2b-256 c30b65d65804371e27d4d04da3b132536937fbcd357e3124a9eb7eea8367612e

See more details on using hashes here.

Provenance

The following attestation bundles were made for exmailer-1.0.0-py3-none-any.whl:

Publisher: pypi_publish.yml on aerosadegh/exmailer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page