Search code examples
c#wcfmicrosoft-graph-api

Send Office 365 email from Wcf Windows Service


We are building a WPF application which communicates with a WCF service (hosted in a Windows Service) for data access, business logic, etc. The application runs on a domain user account, the WCF service on a server account. This WCF service should send emails, create and modify events, etc by using the domain user account. Communicating with Office 365 will be done by Microsoft Graph API, using MSAL and Microsoft Graph Library.

The domains active directory and Azure Active Directory are connected.

How can I connect the Graphs GraphServiceClient using the WCF's ServiceSecurityContext without login dialog? (Map a domain user on a AAD user). Are there any samples available?


Solution

  • What you are looking for is a sample for a 'daemon' service. There is documentation here on this. https://azure.microsoft.com/en-us/resources/samples/active-directory-dotnet-daemon-certificate-credential/

    Essentially you'll need to create a certificate and register it with the Azure AD application. Then when calling the Microsoft Graph, use that certificate so that thee service trusts its really your service.