We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Access on behalf of user via Microsoft Graph

Hi,
Im trying to gain access via Microsoft Graph to a users mail. I have made a Graph Client before, but doing it through Aspose seems to be a challenge.
I would previously create a client like this:

 public static GraphServiceClient CreateGraphClient()
    {
        var tenantId = tenantID;
        var clientId = clientID;
        var clientSecret = secret;

        var options = new TokenCredentialOptions
        {
            AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
        };

        var clientSecretCredential = new ClientSecretCredential(
            tenantId, clientId, clientSecret, options);

        var client = new GraphServiceClient(clientSecretCredential);
        
        return client;
    }

However, if i want a proper conversion to MapiMessage, i need to use the IGraphClient. I cant get this to work with on behalf. Any help is appreciated.

@hoejegaard

We suggest you please read the following article to achieve your requirement.
Working with Microsoft Graph Client

I have looked through that, but honestly the documentation for creating the client is really poor, its litterally one line of code that doesnt explain how to pass any credentials…

IGraphClient client = GraphClient.GetClient(tokenProvider);

Can you please further explain how to gain access on behalf, or how to pass credentials?

@hoejegaard

Please check the attached code example to achieve your requirement. Hope this helps you.
ConsoleAppEwsToGraph.zip (25.8 KB)

1 Like

Thank you very much for your time and answer, this was such a big help.

Thank you for your help. That worked for me! :+1: