Skip to main content

Lightweight SMTP and POP3 mail proxy to Microsoft 365

Project description

SMTP & POP3 Proxy for Microsoft 365 Shared Mailboxes

PyPI version License: MIT GitHub Repo

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.
  • 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_PROXY environment 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.md with structured features and examples
  • Initial docs/ folder with mkdocs.yml and 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


Download files

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

Source Distribution

m365proxy-2.0.0.tar.gz (37.9 kB view details)

Uploaded Source

Built Distribution

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

m365proxy-2.0.0-py3-none-any.whl (39.1 kB view details)

Uploaded Python 3

File details

Details for the file m365proxy-2.0.0.tar.gz.

File metadata

  • Download URL: m365proxy-2.0.0.tar.gz
  • Upload date:
  • Size: 37.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for m365proxy-2.0.0.tar.gz
Algorithm Hash digest
SHA256 e9567c99fd3fe8351c1972a79e5eae579e61657fbeff9734cf4d77d0c0e7f72d
MD5 721b7474569898387ebb24a89d25dc25
BLAKE2b-256 5d5e11f154fe77a7f6007d31d3202c8ee5211ea1db4dda0def474f08fe555be0

See more details on using hashes here.

File details

Details for the file m365proxy-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: m365proxy-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 39.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for m365proxy-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e1e71cedc8743fef3b823a816ab0d34e237ce7e3829d342e1312690913a51d05
MD5 f0efa2b411d74b0f80b311d63e78afcb
BLAKE2b-256 8502048178cf3296821ce505650b3263cde1a205b3612f1ccd0889c5f35d72eb

See more details on using hashes here.

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