Send emails via Microsoft Exchange Server with HTML template support
Project description
Ex(change E)mailer 🐍
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
python3 -m exmailer \
--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.11+
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file exmailer-1.0.5.tar.gz.
File metadata
- Download URL: exmailer-1.0.5.tar.gz
- Upload date:
- Size: 126.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45bfb61ad2cadc364ebb01605f4b32ffe6974847715515a0298b79a4946c0bd8
|
|
| MD5 |
40d28d4e9cb4630789851d1d216828cb
|
|
| BLAKE2b-256 |
2252c70c2ef3fb666632d126eb13ea733c0d42d12d20bbfe04ee6e28790916df
|
Provenance
The following attestation bundles were made for exmailer-1.0.5.tar.gz:
Publisher:
pypi_publish.yml on aerosadegh/exmailer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
exmailer-1.0.5.tar.gz -
Subject digest:
45bfb61ad2cadc364ebb01605f4b32ffe6974847715515a0298b79a4946c0bd8 - Sigstore transparency entry: 943116705
- Sigstore integration time:
-
Permalink:
aerosadegh/exmailer@44b6f70a8c3d2806747085dcc585e068b99fece6 -
Branch / Tag:
refs/tags/v1.0.5 - Owner: https://github.com/aerosadegh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_publish.yml@44b6f70a8c3d2806747085dcc585e068b99fece6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file exmailer-1.0.5-py3-none-any.whl.
File metadata
- Download URL: exmailer-1.0.5-py3-none-any.whl
- Upload date:
- Size: 28.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9b1a2ce2026105d54f1b127759151bd2dda46399486342c53b7ac8e40829c79
|
|
| MD5 |
e1c11c25b012e267370d0afa34bab0f6
|
|
| BLAKE2b-256 |
010b4606185aed99462498a5798b28d63e5812d1b5759bc28ec8d633138e93bd
|
Provenance
The following attestation bundles were made for exmailer-1.0.5-py3-none-any.whl:
Publisher:
pypi_publish.yml on aerosadegh/exmailer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
exmailer-1.0.5-py3-none-any.whl -
Subject digest:
f9b1a2ce2026105d54f1b127759151bd2dda46399486342c53b7ac8e40829c79 - Sigstore transparency entry: 943116726
- Sigstore integration time:
-
Permalink:
aerosadegh/exmailer@44b6f70a8c3d2806747085dcc585e068b99fece6 -
Branch / Tag:
refs/tags/v1.0.5 - Owner: https://github.com/aerosadegh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_publish.yml@44b6f70a8c3d2806747085dcc585e068b99fece6 -
Trigger Event:
push
-
Statement type: