Skip to content

Implement Microsoft OAuth2 authentication for SMTP - #1702

Merged
YoshihitoAso merged 7 commits into
dev-25.12from
feature/mail-xoauth
Dec 17, 2025
Merged

Implement Microsoft OAuth2 authentication for SMTP#1702
YoshihitoAso merged 7 commits into
dev-25.12from
feature/mail-xoauth

Conversation

@purplesmoke05

Copy link
Copy Markdown
Member

📌 Description

This pull request adds support for Microsoft OAuth2 (XOAUTH2) authentication for SMTP email sending, in addition to the existing password-based and Amazon SES methods. It introduces new configuration options, updates the mail sending logic to handle OAuth2 tokens, and provides unit tests to ensure correct behavior for both authentication methods. Documentation is also updated to reflect the new options and configuration matrix.

4. Unit Testing

  • Added comprehensive unit tests for the Mail class to verify both password and XOAUTH2 authentication flows, using mocks to ensure correct SMTP interactions and token handling.

✅ Related Issues

🔄 Changes

Major additions and changes:

1. Microsoft OAuth2 (XOAUTH2) SMTP Support

  • Added support for XOAUTH2 authentication with Microsoft (Azure AD/Entra ID) by introducing new environment variables (SMTP_MS_TENANT_ID, SMTP_MS_CLIENT_ID, SMTP_MS_CLIENT_SECRET, SMTP_MS_REFRESH_TOKEN) and updating the configuration and documentation accordingly. [1] [2] [3] [4]
  • Implemented a TokenProvider abstraction and a MicrosoftTokenProvider class to securely retrieve and cache Microsoft access tokens for SMTP authentication.

2. Mail Sending Logic Updates

  • Modified the Mail class in mail.py to support both password and XOAUTH2 authentication methods, including logic to perform XOAUTH2 authentication with the SMTP server using the access token. [1] [2] [3]

3. Configuration and Documentation

  • Added new environment variables and updated ENV_LIST.md to document all supported SMTP authentication methods, Microsoft OAuth2 settings, and provided a configuration matrix for clarity. [1] [2] [3] [4] [5]

📌 Checklist

  • I have added tests where necessary.
  • I have updated the documentation where necessary.

Comment thread app/config.py
Comment thread app/config.py Outdated
Comment thread app/model/mail/mail.py Outdated

@kyken kyken left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions

github-actions Bot commented Dec 17, 2025

Copy link
Copy Markdown

Coverage

Coverage Report •
FileStmtsMissCoverMissing
app
   config.py107595%61–62, 66, 137, 178
app/model/db
   messaging.py210100% 
app/model/mail
   mail.py801383%67, 73, 80–81, 94, 114–115, 121, 133–134, 154, 156, 159
   token_provider.py661971%46, 75–77, 80–81, 83–84, 87, 89, 95, 109–110, 113–115, 118, 125–126
tests/app/model/mail
   test_mail_unit.py390100% 
   test_token_provider.py960100% 
tests/batch
   processor_Send_Mail_test.py1220100% 
TOTAL45801160296% 

Tests Skipped Failures Errors Time
1538 0 💤 0 ❌ 0 🔥 12m 13s ⏱️

@YoshihitoAso
YoshihitoAso merged commit 03b83be into dev-25.12 Dec 17, 2025
@YoshihitoAso
YoshihitoAso deleted the feature/mail-xoauth branch December 17, 2025 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Support Microsoft 365 email sending via OAuth (SMTP XOAUTH2 and/or Microsoft Graph)

3 participants