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.1.0.tar.gz (37.7 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.1.0-py3-none-any.whl (39.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for m365proxy-2.1.0.tar.gz
Algorithm Hash digest
SHA256 cd44564f624a72f493e8dbb50290075fca8e13762372300c9fa06a7b0aa5dacb
MD5 8fd80cb7d512566ab4ef7f9366433d64
BLAKE2b-256 433f64cd39ef496d44510ad3ec941a0d44e9d1a0036f7f92d05144266f73b850

See more details on using hashes here.

File details

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

File metadata

  • Download URL: m365proxy-2.1.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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce602601322b6422a92f85a18feb9cfa12150c7ec4a6235fba06a5ce42d8b812
MD5 db3d89bd104aaec369412f8c2ba741ae
BLAKE2b-256 7e654d4ab9f3ecc495b995458d0d41d205ae88fa7765b2c46aaba3eb627aa426

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