Skip to content

Releases: ClaneSharke/MailboxReaderClr

v1.1.0 - On-premises Exchange (EWS) support

Choose a tag to compare

@ClaneSharke ClaneSharke released this 19 Sep 08:53

What's new

  • dbo.usp_ReadMailbox_EWS -- a new SQLCLR proc reading an on-premises Exchange mailbox via EWS (Exchange Web Services), Windows/NTLM auth + Exchange Impersonation. Lives alongside the existing Graph-based usp_ReadMailbox in the same assembly.
  • EwsToSqlSync -- a standalone alternative to the EWS proc: a plain .exe you run on a schedule via Windows Task Scheduler, using the same EWS logic but writing to SQL Server with an ordinary login instead of SQL Server CLR. No assembly registration, no trust hashes. Includes MessageId-keyed dedupe so repeat scheduled runs don't insert duplicate rows.
  • Deploy-EWS.sql, Deploy-Full-Remote.sql (fully self-contained deploy with the DLL bytes embedded as a hex literal, so there's no separate .dll file needed on the target server), and Drop-And-Recreate.sql (clean re-deploy when a stale assembly is registered).
  • README.md documents both approaches side by side with a comparison table, plus setup steps for each.

Attached binaries

  • MailboxReaderClr.dll -- built from this tag, net472, contains both MailReader (Graph) and EwsMailReader (EWS)
  • EwsToSqlSync.exe -- the standalone scheduled-task alternative (needs config.json alongside it, see EwsToSqlSync/config.example.json)

Both are provided for convenience; building from source (dotnet build -c Release) remains fully supported and gives you full control over what SQL Server or Task Scheduler ends up trusting/running.

Known limitation

The EWS-based code (both the SQLCLR proc and EwsToSqlSync) has not yet been verified against a live on-premises Exchange server. Treat the exact SOAP request/response shape as a strong first draft to validate against your own Exchange version/CU, per the Troubleshooting sections in README.md.

v1.0.1

Choose a tag to compare

@ClaneSharke ClaneSharke released this 09 Sep 10:40

Bug fix release.

Fixed

  • Msg 10301 ... references assembly 'system.web.extensions' ... which is not present in the current database when running CREATE ASSEMBLY / calling the proc.
    • Root cause: v1.0.0 used JavaScriptSerializer (System.Web.Extensions), which SQL Server's CLR host does not auto-trust the way it does mscorlib/System/System.Data -- it needed its own separate registration, contradicting the project's whole "only your own assembly needs registering" design.
    • Fix: replaced it with JsonMini.cs, a small dependency-free JSON parser. MailboxReaderClr.dll now references only mscorlib, System, and System.Data -- confirmed via Assembly.GetReferencedAssemblies().

If you deployed v1.0.0 and hit this error: drop the old assembly and trusted-assembly entry, then redeploy using this release's DLL/Deploy.sql/Deploy-Remote.sql.

DROP PROCEDURE dbo.usp_ReadMailbox;
DROP ASSEMBLY MailboxReaderClr;
-- find the old hash: SELECT * FROM sys.trusted_assemblies;
EXEC sys.sp_drop_trusted_assembly @hash = <old hash>;

No functional/parameter changes since v1.0.0 -- same dbo.usp_ReadMailbox signature, both app-only and delegated password (ROPC) auth modes.

v1.0.0

Choose a tag to compare

@ClaneSharke ClaneSharke released this 09 Sep 09:25

Initial public release.

Features

  • dbo.usp_ReadMailbox SQLCLR stored procedure that reads messages from an Exchange Online / Office 365 mailbox directly from T-SQL via the Microsoft Graph API.
  • No third-party NuGet dependencies -- uses HttpWebRequest directly, so only your own compiled assembly needs to be registered in SQL Server (via hash-based sys.sp_add_trusted_assembly, no certificate signing or TRUSTWORTHY needed).
  • Two auth modes:
    • App-only (default) -- client_credentials grant via Tenant/Client/ClientSecret, scoped to one mailbox via an Exchange Online Application Access Policy.
    • Delegated password (ROPC), optional -- pass @Password to authenticate as the mailbox itself instead. Documented with its MFA/Conditional Access caveats; app-only is the recommended default.

Setup
See README.md for Azure AD app registration steps (both modes) and Deploy.sql for the SQL-side registration script and usage examples.

Requirements

  • SQL Server 2017 CU12+ / 2019+ (for hash-based trusted-assembly registration)
  • .NET Framework 4.7.2 targeting pack to build

Build it yourself: clone, dotnet build -c Release, then run Deploy.sql against your target database.