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.2.6.tar.gz (38.0 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.2.6-py3-none-any.whl (39.3 kB view details)

Uploaded Python 3

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

Hashes for m365proxy-2.2.6.tar.gz
Algorithm Hash digest
SHA256 745e5ab4953589d119a6a645d83d84b3b2aece08255155f1c658ddf76f946f97
MD5 d09d19a5a2786983dcfe21e044425851
BLAKE2b-256 003cb9361f52cfe589a494715d8b4dbcb6f308ee78ada58d396650c60b2bdfeb

See more details on using hashes here.

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

Hashes for m365proxy-2.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9db4750878f1e53b4dd8024f647d508301fcbb6a9fdac31354449bca10dd8d09
MD5 52e329f9341da6ec44964261f2b69aed
BLAKE2b-256 a502fec53fa3afd880195b984d3b6366519a222b8de4ec0216fcc7a1bd4c74f3

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