Skip to content

JustinIven/smtp-oauth-relay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SMTP OAuth Relay

An SMTP relay that accepts SMTP submissions from legacy clients and forwards messages to Microsoft Graph using OAuth 2.0 client credentials.

Overview

This repository implements a small, stateless SMTP server that bridges the gap between legacy SMTP clients and Microsoft 365's modern authentication requirements:

  • πŸ”’ OAuth 2.0 Authentication: Uses application credentials instead of user passwords
  • πŸ“§ Microsoft Graph Integration: Sends email via the Microsoft Graph API
  • πŸ”Œ SMTP Compatibility: Works with any SMTP client (AUTH LOGIN/PLAIN)
  • πŸš€ Stateless & Scalable: Can be deployed in multiple instances for high availability
  • πŸ” Security-First: Supports TLS encryption and Azure Key Vault integration
  • πŸ“Š Azure Tables Support: Optional centralized credential management

Comparison with Other Solutions

Feature SMTP OAuth Relay Azure Communication Services Microsoft 365 High Volume Email (Preview)
Purpose Bridge legacy SMTP clients to Microsoft 365 General email/SMS/voice service High-volume transactional email
Use Case Legacy devices, printers, apps without OAuth Application email/SMS at scale Marketing, newsletters, bulk email
SMTP Support βœ… SMTP compatibility βœ… SMTP available βœ… SMTP compatibility
Send Externally βœ… Yes (to any recipient) βœ… Yes (to any recipient) ❌ No (only internal)
Legacy Device Support βœ… Excellent ⚠️ Moderate* βœ… Excellent
Multi-tenant βœ… Yes ❌ No ❌ No
Sender Address Uses existing M365 mailboxes Custom domains Uses dedicated Mailbox (HVE-Account)
Pricing Free (self-hosted) Pay-per-use (email/SMS/calls) Free in Preview
Infrastructure Self-hosted (Docker/K8s) Fully managed Azure service Fully managed Microsoft service
Deliverability Microsoft 365 reputation Separate IP pools and reputation Microsoft 365 reputation
Volume Limits Based on M365 mailbox limits Very high (purpose-built for scale) Very high (designed for bulk)
Setup Complexity Moderate (deploy + Entra app) Moderate (provision resource + Entra app) Low (create HVE-Account)

*Some legacy devices may not support providing a dedicated From address or may implement a character limit, which won't work with ACS.

Quick Start

Deploy on Azure

Deploy to Azure

Refer to the Installation Guide for detailed steps.

Run with Docker

docker run --name smtp-relay -p 8025:8025 \
  -v $(pwd)/certs:/usr/src/smtp-relay/certs \
  -e LOG_LEVEL=INFO \
  -e TLS_SOURCE=file \
  -e REQUIRE_TLS=true \
  ghcr.io/justiniven/smtp-oauth-relay:latest

Basic Configuration

Setting Value
SMTP Server Your relay hostname
Port 8025
Security STARTTLS
Username tenant_id@client_id
Password Your app's client secret

Documentation

πŸ“˜ Getting Started

πŸ”§ Configuration

πŸ—οΈ Architecture & Help

Features

Authentication Options

Direct UUID Format:

12345678-1234-1234-1234-123456789abc@abcdefab-1234-5678-abcd-abcdefabcdef

Base64URL Encoded (shorter):

EjRWeBI0EjQSNBI0VnirzQ@q83rrBI0VnirzN21q837qg

Azure Tables Lookup (custom):

printer1@lookup

TLS Certificate Sources

  • File: Load from filesystem (development, production with Let's Encrypt)
  • Azure Key Vault: Managed certificate storage with automatic rotation
  • Off: Disable TLS (development only)

Advanced Features

  • βœ… Multiple tenant support (single relay for multiple organizations)
  • βœ… Application Access Policies integration (restrict sender addresses)
  • βœ… Azure Tables for simplified credentials
  • βœ… Sender address override
  • βœ… Horizontal scaling (stateless design)
  • βœ… Comprehensive logging and monitoring

Architecture

Authentication Flow

Use Cases

Legacy Devices

  • Network printers with scan-to-email
  • Multifunction devices
  • Fax servers
  • Security cameras

Applications

  • Monitoring systems (Grafana, Nagios)
  • CI/CD pipelines (Jenkins, GitLab)
  • Content management systems (WordPress, Drupal)
  • Custom applications without OAuth support

Network Infrastructure

  • NAS devices (Synology, QNAP)
  • Firewalls and routers
  • UPS systems
  • IoT devices

Requirements

Server Requirements

  • Python 3.11+ (if running manually)
  • Docker (recommended) or Kubernetes
  • Network access to Microsoft APIs
  • TLS certificate (production)

Azure Requirements

  • Microsoft 365 / Exchange Online tenant
  • Microsoft Entra ID (Azure AD)
  • Application registration with Mail.Send permission

Optional

  • Azure Key Vault (for certificate management)
  • Azure Table Storage (for credential lookup)
  • Managed Identity (for Azure services)

Security

This relay implements security best practices:

  • πŸ” TLS Encryption: Protects credentials in transit
  • πŸ”‘ OAuth 2.0: No user passwords stored or transmitted
  • πŸ›‘οΈ Application Permissions: Centrally managed in Azure
  • πŸ“ Audit Logging: Full activity logs in Azure AD
  • 🚫 Access Policies: Restrict sender addresses
  • πŸ”„ Secret Rotation: Regular credential rotation support

Community & Support

  • πŸ“– Documentation: Comprehensive guides in the docs/ folder
  • πŸ› Bug Reports: GitHub Issues
  • πŸ’‘ Feature Requests: GitHub Issues
  • 🀝 Contributions: Pull requests welcome!

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Acknowledgments

Built with:


Ready to get started? β†’ Installation Guide

About

Lightweight SMTP relay, that forwards E-Mails to Microsoft Graph

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 2

  •  
  •