Suppose we want to Approve the Email for the mailbox of the user(s) programmatically.
We’d see the below notification for the user whose mailbox is not yet approved.
Email won’t be processed for this mailbox until the email address of the mailbox is approved by an Office 365 Global Administrator or by an Exchange Administrator. For more information, contact your system administrator.

Below is the sample code –

On running the code, we can see the notification for the email address approval removed or the mailbox approved for the user.

C# Code –
CrmServiceClient svc = new CrmServiceClient(ConnectionString);
if (svc.IsReady)
{
var systemUser = new Entity("systemuser", new Guid("C48A539A-F493-EC11-B400-000D3A4F37D3"));
// emailrouteraccessapproval - status of the primary email address
//0 = Empty, 1 = Approved, 2 = Pending Approval, 3 = Rejected
systemUser.Attributes["emailrouteraccessapproval"] = new OptionSetValue(1);
svc.Update(systemUser)
The code should run under the context of the user who has either Global Admin or Exchange Admin role.
Hope it helps..
2 thoughts on “Sample Code to Approve Email – Mailbox programmatically C# (Dynamics 365/CRM)”