Lightweight SMTP and POP3 mail proxy to Microsoft 365
Project description
SMTP & POP3 Proxy for Microsoft 365 Shared Mailboxes
Why This Project?
Many legacy systems, embedded devices, and applications:
- โ Do not support OAuth2 for sending or receiving email
- โ Cannot access Microsoft 365 endpoints directly due to network restrictions
- โ Require SMTP/POP3 and basic username/password authentication
This proxy provides a secure bridge between those tools and Microsoft 365:
- ๐ก๏ธ Messages are relayed through a single authenticated Microsoft 365 account
- ๐ Only authorized clients (defined in config) can use the proxy
- ๐ Useful when you can't expose your own mail servers in SPF records
- ๐ฅ Enables retrieval of mail from shared mailboxes via POP3
- ๐ธ With a single low-cost Exchange Online Kiosk license + free shared mailboxes, you can build a distributed, multi-sender notification system โ without a full SMTP infrastructure
Ideal for:
- Network monitoring software
- Firewalls, routers, printers, IP cameras
- IoT and industrial equipment
- Legacy on-prem systems
- Environments with no internet access or firewall egress rules
This tool helps consolidate notifications from many devices and subsystems under one tenant, while still keeping SPF clean.
โจ New Features (v2)
- ๐ POP3 STARTTLS support โ mail clients can now upgrade plaintext POP3 connections to TLS securely
- ๐ SMTP SMTPS support (TLS from start) โ SMTPS (port 465) is now supported in addition to STARTTLS (port 587 or custom)
- ๐ POP3S support (TLS from start) โ full support for POP3 over SSL/TLS (port 995)
- ๐ Simultaneous operation of all modes โ you can now run:
- SMTP (with STARTTLS)
- SMTPS (SSL/TLS)
- POP3 (with STARTTLS)
- POP3S (SSL/TLS) โฆon different ports, either individually or together
- ๐ Improved configuration parser:
- Clearer validation of TLS, ports, logging paths, and mailbox entries
- Prevents conflicts like
smtp_port == smtps_port - Enhanced proxy URL formatting and diagnostics
- ๐ค Better compatibility with popular clients and devices:
- Thunderbird, Outlook, MFDs, embedded IoT mailers, etc.
- โ Final release for this stage โ future possibilities (IMAP, shared calendars, folders) may push the project into enterprise mail territory, which goes beyond the scope and potentially conflicts with Microsoft licensing โ and thatโs not a direction this project is taking.
Overview
This tool is designed for cases where you want to use real mail clients and devices (like scan-to-email from printers or backup software) with Microsoft 365 but want to avoid exposing user credentials or managing OAuth2 flows manually.
It provides local endpoints (SMTP and POP3) that forward requests securely via Microsoft Graph.
Features
- โ
Transparent mail sending via Microsoft Graph
/sendMail - โ Works with shared mailboxes ("Send As")
- โ Supports large attachments (up to 150MB via Graph API chunked upload)
- โ POP3 receiving, with folder selection and message flags
- โ Shared folder access for POP3 download (e.g. service@domain.com)
- โ STARTTLS and SMTPS support
- โ Multiple mailboxes with independent credentials
- โ Authenticated and secure
- โ Python-based and container-ready
๐ Quick Start
pip install m365proxy
# First-time login to Microsoft 365 via Device Flow
m365proxy --login
# Start the proxy (SMTP + POP3)
m365proxy run
๐ Configuration (config.json)
Example:
{
"user": "admin@tenant.onmicrosoft.com",
"client_id": "YOUR-APP-ID",
"tenant_id": "YOUR-TENANT-ID",
"mailboxes": [
{ "username": "alerts@tenant.onmicrosoft.com", "password": "secret" }
],
"bind": "127.0.0.1",
"smtp_port": 2525,
"pop3_port": 110,
"tls": {
"tls_cert": "cert.pem",
"tls_key": "key.pem"
},
"attachment_limit_mb": 80
}
๐ฆ Offline Mode & Queue
When Microsoft 365 is unreachable:
- โ๏ธ Messages are queued to disk
- ๐ Automatically retried in background (every 5 minutes)
- ๐ง No data loss โ even if the device is offline for hours
You can inspect the queue at:
ls ~/.m365proxy/queue/
๐ก Architecture
Legacy Device (SMTP) โโโโโโ
โโ> SMTP Proxy โโ> Graph API โโ> Exchange Mailbox
App / Printer / Camera โโโ
POP3 Client <โโโโโโโโโโโโโโ POP3 Proxy <โโโ Graph API (Shared Mail)
๐ชช Licensing
MIT ยฉ sh0rch โข See LICENSE
๐ฆ Changelog โ m365proxy
[1.2.0] - 2025-05-04
โจ New Features
- Fully asynchronous SMTP and POP3 proxy
- The proxy server is now built entirely on
asyncio, allowing non-blocking performance and better concurrency.
- The proxy server is now built entirely on
- SMTP queue and offline resend support
- Outgoing messages are stored on disk and retried automatically when Graph API becomes reachable.
- HTTPS proxy support via
HTTPS_PROXYenvironment variable- Enables deployment behind corporate or cloud proxies.
- Safe resend without duplication
- The queue system is aware of delivery status to prevent double-sending.
- AUTH PLAIN and AUTH LOGIN for POP3
- Compatible with Outlook, Thunderbird, and other standard clients.
๐ง Improvements
- Improved logging of network/API failures
- Graph API 405/403 responses treated as valid reachability indicators
- Added architectural diagram and offline-mode documentation
- Enhanced
README.mdwith structured features and examples - Initial
docs/folder withmkdocs.ymland Markdown pages
โ ๏ธ Upgrade Notes
- Python 3.9 or higher is recommended
start_smtp_server()is now async and must be awaited- Queue processing and token refresh now run as background tasks
MIT ยฉ 2025 sh0rch
Project details
Release history Release notifications | RSS feed
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 m365proxy-2.2.6.tar.gz.
File metadata
- Download URL: m365proxy-2.2.6.tar.gz
- Upload date:
- Size: 38.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
745e5ab4953589d119a6a645d83d84b3b2aece08255155f1c658ddf76f946f97
|
|
| MD5 |
d09d19a5a2786983dcfe21e044425851
|
|
| BLAKE2b-256 |
003cb9361f52cfe589a494715d8b4dbcb6f308ee78ada58d396650c60b2bdfeb
|
File details
Details for the file m365proxy-2.2.6-py3-none-any.whl.
File metadata
- Download URL: m365proxy-2.2.6-py3-none-any.whl
- Upload date:
- Size: 39.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9db4750878f1e53b4dd8024f647d508301fcbb6a9fdac31354449bca10dd8d09
|
|
| MD5 |
52e329f9341da6ec44964261f2b69aed
|
|
| BLAKE2b-256 |
a502fec53fa3afd880195b984d3b6366519a222b8de4ec0216fcc7a1bd4c74f3
|