Repository navigation
Releases: ClaneSharke/MailboxReaderClr
Release list
v1.1.0 - On-premises Exchange (EWS) support
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-basedusp_ReadMailboxin 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), andDrop-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 bothMailReader(Graph) andEwsMailReader(EWS)EwsToSqlSync.exe-- the standalone scheduled-task alternative (needsconfig.jsonalongside it, seeEwsToSqlSync/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
Bug fix release.
Fixed
Msg 10301 ... references assembly 'system.web.extensions' ... which is not present in the current databasewhen runningCREATE 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 doesmscorlib/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.dllnow references onlymscorlib,System, andSystem.Data-- confirmed viaAssembly.GetReferencedAssemblies().
- Root cause: v1.0.0 used
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
Initial public release.
Features
dbo.usp_ReadMailboxSQLCLR 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
HttpWebRequestdirectly, so only your own compiled assembly needs to be registered in SQL Server (via hash-basedsys.sp_add_trusted_assembly, no certificate signing orTRUSTWORTHYneeded). - Two auth modes:
- App-only (default) --
client_credentialsgrant via Tenant/Client/ClientSecret, scoped to one mailbox via an Exchange Online Application Access Policy. - Delegated password (ROPC), optional -- pass
@Passwordto authenticate as the mailbox itself instead. Documented with its MFA/Conditional Access caveats; app-only is the recommended default.
- App-only (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.