CanIPhish can integrate directly with Microsoft 365 through the Graph API. Using this API we can inject simulated phishing and notification emails directly into employee inboxes using a technique known as Direct Email Injection (DMI for short), bypassing the need for traditional email allowlisting!
Important Note: This guide should only be followed if you have set up platform white-labelling. If you haven't, please follow this setup guide.
Important: Open the platform on your white-labelled domain. The form for your app registration's details only appears when you're signed in on your white-labelled domain (for example, phish.mybusiness.com). On caniphish.com, selecting Microsoft 365 starts the Sign in with Microsoft flow from the standard setup guide instead.
Table of Contents
- Before You Start: Choose A Credential
- Step 1. Create An App Registration In Microsoft
- Step 2. Configure Direct Email Injection In CanIPhish
- Step 3. Switch An Existing Integration To A Federated Credential (Optional)
- Frequently Asked Questions
Before You Start: Choose A Credential
The platform signs in to your Microsoft app registration with one of two credentials. You choose one in the platform's form in Step 2:
- Client secret: a password-like value that you create in Microsoft Entra and paste into the platform. This is the option the platform has always offered. A client secret expires, so before it does, you have to create a new one and update the integration.
- Federated credential (recommended where possible): instead of a secret, you add a federated credential to the app registration. It trusts the platform's issuer for one exact subject, which identifies this integration. Microsoft calls this workload identity federation. There's no secret to create, share, store or rotate, and it works in tenants whose policy blocks new client secrets.
Which steps to follow:
- Client secret: Steps 1.1 to 1.18, then Steps 2.1 to 2.6 and 2.14 to 2.17.
- Federated credential: Steps 1.1 to 1.14 (don't create a client secret), then Steps 2.1 to 2.5 and 2.7 to 2.17.
- An existing integration that uses a client secret: switch it in place with Step 3.
Important for a federated credential: the order matters. The subject you add in Entra comes from the platform's form. Open the form, choose Federated credential, name the integration and copy the issuer and subject (Steps 2.1 to 2.8) before you add the credential in Entra (Steps 2.9 to 2.12). Then return to the form and click Save (Step 2.13).
Step 1. Create An App Registration In Microsoft
Note: The Microsoft steps in this guide should be done by a Global Administrator of the Microsoft 365 tenant you're connecting. Microsoft doesn't allow emails to be injected into a tenant without that tenant's consent, and granting admin consent to Microsoft Graph application permissions (Step 1.14) typically needs a Global Administrator. If you manage the platform for a customer, their administrator can do the Microsoft steps for you. They don't need to sign in to the platform:
- Client secret: they complete Steps 1.1 to 1.18 and send you the Application ID, Tenant ID and client secret value.
- Federated credential: you start in the platform with Steps 2.1 to 2.8 and send them the issuer and subject. They complete Steps 1.1 to 1.14 and 2.9 to 2.12, then send you back only the Application ID and Tenant ID. You finish with Step 2.13. Nothing secret changes hands.
1.1. Sign in to the Microsoft Azure portal with an account in your Microsoft 365 tenant: https://portal.azure.com/
1.2. In the search bar at the top of the page, search for App registrations and click the corresponding service.
1.3. Click New registration to create a new app registration:
1.4. Give the app a unique and distinguishable name (e.g. CanIPhish DMI Connector), leave the other options on their default settings (as shown below) and then click Register:
1.5. While on the Overview page, copy the Application (client) ID and Directory (tenant) ID values to your clipboard or a text editor, as you'll need them later:
1.6. Click Manage > API permissions on the left:
1.7. Click Add a permission:
1.8. Click the Microsoft Graph API:
1.9. Click Application permissions (not Delegated permissions):
1.10. In the search box, type Mail.ReadWrite, then expand the Mail permission and select Mail.ReadWrite (Read and write mail in all mailboxes).
1.11. Now change the search to User.Read.All, then expand the User permission and select User.Read.All (Read all users' full profiles).
1.12. Click Add permissions at the bottom of the page to add the two permissions you've selected:
1.13. Confirm that both permissions appear in the API permissions table:
1.14. A warning appears next to each permission, showing that admin consent hasn't been granted yet. The permissions don't work without it, and the platform checks for it when you save the integration. Click the Grant admin consent for button (followed by your tenant's name) directly above the table. Afterwards, the Status column shows that access has been granted.
Client Secret Only
Using a federated credential? Skip Steps 1.15 to 1.18 and don't create a client secret. If you're signed in to the platform, go to Step 2: you'll add the federated credential in Entra in Steps 2.9 to 2.12, once the platform has shown you its subject. If someone sent you the issuer and subject, go straight to Step 2.9 (under With A Federated Credential).
1.15. Now go to Manage > Certificates & secrets:
1.16. Click New client secret. If your organisation's policy blocks new client secrets, Entra won't let you add one: use a federated credential instead.
1.17. In the panel that appears on the right of your screen, give the secret a descriptive name (e.g. "CanIPhish DMI Connector Secret") and an expiry. We recommend the maximum of 730 days (when it expires, you need to create a new secret; see the FAQ below). Then click Add:
1.18. Your secret now appears in the Client secrets table. Copy its Value (not its Secret ID) to your clipboard or a text editor. Entra only shows the value right after you create it.
Step 2. Configure Direct Email Injection In CanIPhish
2.1. Sign in to the platform on your white-labelled domain. In the sidebar, under Configuration, click Platform Settings, then click Email Delivery Settings on the Platform Settings tab. The Manage Email Delivery Providers page opens in a new tab (/platform/email-delivery-providers on your white-labelled domain). If you manage several customers, check that the customer you're connecting is shown as the Current Tenant. You need the Platform Super Admin or Platform Admin role: Email Delivery Settings isn't shown otherwise.
2.2. Click New Email Provider, then select Microsoft 365. The Set up Direct Email Injection for Microsoft 365 dialog opens. If you see a Sign in with Microsoft button instead, you're not on your white-labelled domain, or white-labelling isn't active (published) for that domain yet.
2.3. Under Name the integration, enter a unique and distinguishable name (e.g. "M365 DMI Connector"). The platform keeps the letters A to Z and the digits 0 to 9, in the case you typed them, and turns every other character, including spaces and accented letters, into a hyphen, so "M365 DMI Connector" is saved as M365-DMI-Connector. The name can't be changed later, and for a federated credential it's part of the subject. Use a name whose saved form isn't already in your list of email delivery providers (for example, "M365 DMI" and "M365-DMI" are the same once saved): saving with a name that's already in use replaces that provider, whatever type it is.
2.4. Under Application (client) ID and Directory (tenant) ID, paste the values you copied in Step 1.5. Use the tenant ID itself, not a domain name such as contoso.onmicrosoft.com. If a customer's administrator is setting up a federated credential for you and you don't have these values yet, leave them empty for now and carry on: you'll enter them in Step 2.13.
2.5. Under Credential, select the option you chose, then follow the matching part below:
- Client secret: Step 2.6 (With A Client Secret).
- Federated credential: Steps 2.7 to 2.13 (With A Federated Credential).
With A Client Secret
2.6. Select Client secret (selected by default), paste the value you copied in Step 1.18 under Client secret and click Save. Then continue at Step 2.14.
With A Federated Credential
Do Steps 2.7 to 2.13 in this order. The subject you add in Entra comes from this dialog, so copy it before you open Entra, and don't click Save until the credential has been added in Entra.
2.7. Select Federated credential. The Client secret field is replaced by two read-only boxes: Issuer, which is always https://id.caniverify.com, and Subject. The subject identifies this integration on the platform. It starts with workspace: followed by the platform's own ID for your tenant on the platform (for partners, the customer shown as Current Tenant). That ID isn't your Microsoft tenant ID, so don't change it. The subject ends with the integration name as it will be saved (for example …:injection:M365-DMI-Connector) and updates as you type the name. If it says Name the integration first, enter a name (Step 2.3).
2.8. Click the copy button next to Issuer and paste the value somewhere you can get to it, such as a text editor. Do the same for Subject. Don't change the name after this: the subject changes with it, so if you do change it, copy the subject again. Don't click Save yet: keep this dialog open and do Steps 2.9 to 2.12 in another browser tab. While the dialog is open, don't switch to another customer (Current Tenant) in any browser tab. If you did, reload this page, open the dialog again and copy the subject again before you add it in Entra. If the dialog closes, open it again (Step 2.2) and enter exactly the same name. The subject stays the same as long as you're working in the same tenant on the platform (for partners, the same customer shown as Current Tenant, Step 2.1).
If a customer's administrator is doing the Microsoft part: send them the issuer and subject (neither is secret), together with Steps 1.1 to 1.14 and 2.9 to 2.12 of this guide (or a link to it, if you share CanIPhish resources with your customers). They complete those steps, then send you back the Application ID and Tenant ID. Then continue at Step 2.13.
2.9. In the Azure portal (search for App registrations, as in Step 1.2) or the Microsoft Entra admin center (Entra ID > App registrations), open the app registration you created in Step 1. Under Manage, select Certificates & secrets, select the Federated credentials tab, then click Add credential.
2.10. In the Add a credential panel, set Federated credential scenario to Other issuer.
2.11. Fill in the fields as follows:
-
Issuer: paste the issuer you copied:
https://id.caniverify.com. It must match exactly, with no trailing slash or spaces. - Type: leave Explicit subject identifier selected. Don't use Claims matching expression (Preview).
- Value (called Subject identifier in some versions of the panel): paste the subject you copied in Step 2.8, or the one you were sent.
-
Name: a name for the credential in Entra (e.g.
CanIPhish-DMI-Connector). It must be 3 to 120 characters long, use only letters, digits, hyphens and underscores, and start with a letter or digit. It can't be changed later. - Description: optional.
-
Audience: leave it as
api://AzureADTokenExchange(Entra's default) and don't edit it. This includes GCC tenants, which are in Microsoft's global cloud. Only two kinds of tenant need a different value: in a US Government GCC High tenant the audience must beapi://AzureADTokenExchangeUSGov, and in a China (21Vianet) tenant it must beapi://AzureADTokenExchangeChina. In those tenants, check what the box shows and, if it shows anything else, edit it to that value.
Important: The issuer and subject must match the platform's values exactly, including upper and lower case, so copy and paste them rather than typing them. Entra accepts wrong values without any warning; a mistake only shows up when the platform checks the connection in Step 2.13. Because the subject includes the integration's name, an integration with a different name needs its own federated credential (see the FAQ below).
2.12. Click Add. The credential now appears on the Federated credentials tab. If you're a customer's administrator doing only the Microsoft part, you're done: send the Application (client) ID and Directory (tenant) ID (Step 1.5) back to whoever sent you the issuer and subject.
2.13. Go back to the platform's Set up Direct Email Injection for Microsoft 365 dialog. If you closed it or reloaded the page, open it again (Step 2.2), enter exactly the same name and select Federated credential. Enter the Application ID and Tenant ID if you haven't yet (Step 2.4), check that Federated credential is still selected and that the Subject is the one you added in Entra, then click Save. A credential added in the last few minutes may not be recognised by Entra yet: if saving fails with Entra didn't accept the federated credential, wait a few minutes and click Save again before you change anything.
Check And Test The Integration
2.14. When you click Save, the platform checks the connection to Microsoft 365 before it saves anything. This can take up to 30 seconds. It signs in with the details you entered and checks that the app registration has the Mail.ReadWrite and User.Read.All application permissions with admin consent. No email is sent. If the check fails, nothing is saved and an Integration Error message explains why (see the FAQ below): fix the problem and click Save again. When the check passes, the page reloads and shows The direct email injection integration has been saved. If the platform's own mail servers are still your default, you may be asked Make this your default?
2.15. The new integration now appears in the Manage Email Delivery Providers table under its saved name, with Microsoft 365 Direct Email Injection (Manual) as its service provider, followed by (federated) if it uses a federated credential. To test it, open the actions menu (⋮) on its row and choose Test connectivity:
2.16. In the Test Microsoft 365 connectivity popup, enter the address the test should go to under Send a test email to (it starts with your own address; if you're connecting a customer, replace it with a mailbox in that customer's Microsoft 365 tenant) and click Send test email. The address's domain must exactly match one of your verified domains. The test places an unread email titled Integration Test, from M365 DMI Test, in that mailbox's Inbox. This confirms that CanIPhish has sufficient privileges to insert emails into user account inboxes, and that the provided email address can be located within the linked Microsoft 365 account.
2.17. If you see Integration Successful, you're all done! If you see Integration Error, the message explains why, for example a domain that isn't verified, missing permissions, or an address that isn't a mailbox in the connected Microsoft 365 tenant. As a final and optional step, set the new integration as your default delivery provider: open the actions menu (⋮) on its row and choose Set as default. The default is selected whenever a new campaign is created and is used for most notifications. A few emails sent directly from the platform, such as report emails, still go through the platform's own mail servers. Existing campaigns keep the mail server they were created with; see Troubleshooting: Direct Email Injection.
Important Note: If you use M365 Safe Link/Attachment Processing, you'll need to implement rules to bypass this scanning. Please see our Bypass Safe Link/Attachment Processing for M365 knowledgebase article.
Step 3. Switch An Existing Integration To A Federated Credential (Optional)
Only follow this step for an existing integration that uses a client secret. It switches the integration to a federated credential in place: the integration keeps its name, so campaigns and notifications that use it carry on unchanged. A new integration set up with a federated credential in Step 2 doesn't need it.
3.1. On the Manage Email Delivery Providers page (Step 2.1), open the actions menu (⋮) on the integration's row and choose Update integration. The Update Direct Email Injection for Microsoft 365 dialog shows the integration's name, which can't be changed, and its Application ID and Tenant ID.
3.2. Under Credential, select Federated credential. The Issuer and this integration's Subject appear, built from its existing name. If the Subject box says This name can't be used in a federated credential, this integration can't be switched: keep its client secret, or set up a new integration with a federated credential (Step 2).
3.3. Copy the issuer and subject, then add a federated credential with them to the same app registration (the one whose Application ID is shown), as in Steps 2.9 to 2.12. Leave the client secret in Entra for now. If a customer's administrator is doing the Microsoft part, send them the issuer and subject (neither is secret) and close the dialog. They add the credential as in Steps 2.9 to 2.12.
3.4. Back in the dialog, click Save. If you closed it, choose Update integration again and select Federated credential (the dialog shows Client secret until the switch is saved), check that the Subject is the one added in Entra, then click Save. The platform checks the connection with the federated credential before it changes anything. If the check fails, nothing changes and the integration keeps using its client secret. If it passes, the integration switches to the federated credential and the stored client secret is removed from the platform. You'll see The direct email injection integration has been updated.
3.5. The Service Provider column now shows (federated) after Microsoft 365 Direct Email Injection (Manual). You can run Test connectivity again to confirm delivery (Steps 2.15 to 2.17).
3.6. In Entra, open the app registration's Certificates & secrets page, select the Client secrets tab and delete the old client secret, unless something else still uses it.
Frequently Asked Questions
What happens if a user doesn't exist within the Microsoft 365 Tenant?
If the user is sent a simulated phishing email, the campaign shows Failure - Employee Not Found In Microsoft 365 next to their email address. If the user is sent a notification, then a fallback to use CanIPhish email servers will occur to ensure the notification is still sent.
What happens when the client secret expires?
Emails can no longer be injected, and campaigns that use the integration show Failure - Employee Not Found In Microsoft 365 for every employee. Ideally before it expires, create a new client secret (Steps 1.15 to 1.18), then open the actions menu (⋮) on the integration's row, choose Update integration, check that Client secret is selected, enter the new value under Client secret and click Save. The new secret is checked before it's saved. To stop replacing secrets, switch the integration to a federated credential instead (Step 3).
Does a federated credential expire?
No. A federated credential has no expiry date, so there's nothing to replace. It keeps working as long as it stays on the app registration with the same issuer and subject, and the app keeps its permissions.
Can I change an integration's name?
No. The name can't be changed after it's saved, and for a federated credential it's part of the subject that Entra matches exactly. To use a different name, set up a new integration (Step 2) and add a new federated credential in Entra for its new subject. Then set the new integration as your default if needed, and delete the old integration and its federated credential once you no longer need them. Existing campaigns keep using the integration they were created with, and the platform won't delete an integration that a campaign still uses (Error - Mail instance currently in-use.).
Can I change the Application ID or Tenant ID later?
Yes. Choose Update integration, change them and click Save. The platform never shows the stored client secret, so with a client secret you need to enter it again, even if it hasn't changed. With a federated credential, the subject stays the same, so the app registration you're moving to needs a federated credential with the same issuer and subject (Steps 2.9 to 2.12).
How do I switch from a federated credential back to a client secret?
Create a client secret (Steps 1.15 to 1.18), choose Update integration, select Client secret, enter the secret's value and click Save. Once it's saved, delete the federated credential in Entra (Certificates & secrets, Federated credentials tab) unless something else still uses it.
My organisation blocks new client secrets. Can I still connect?
Yes. Use a federated credential: there's no client secret to add, so a policy that blocks new client secrets (such as Microsoft's Block password addition policy) doesn't get in the way. Some organisations also restrict federated credentials. If a correctly added federated credential still can't sign in (usually The app registration couldn't sign in with these details), check with your Microsoft administrator.
Saving fails with an Integration Error. What does the message mean?
- Entra didn't accept the federated credential: the issuer or subject in Entra doesn't exactly match the platform's (check upper and lower case, spaces and trailing slashes), the audience isn't the one given in Step 2.11, or the credential was added to a different app registration (one that has other federated credentials) from the one whose Application ID you entered. A credential added in the last few minutes may not be recognised yet: wait a few minutes and click Save again.
- No app registration with that Application ID was found in that tenant: check the Application ID and Tenant ID (Step 1.5).
- That Tenant ID wasn't found: enter the Directory (tenant) ID from the app registration's Overview page (Step 1.5).
- Please ensure a valid Application ID and Tenant ID are supplied (or Application ID, Tenant ID, and Client Secret): these IDs only contain letters, digits and hyphens, so a domain name such as contoso.onmicrosoft.com isn't accepted. Use the values from Step 1.5.
- Invalid Client Secret: paste the secret's Value, not its Secret ID (Step 1.18).
- The app registration signed in, but it can't deliver email into mailboxes: add Mail.ReadWrite and User.Read.All as application permissions and grant admin consent (Steps 1.6 to 1.14).
- The app registration couldn't sign in with these details: check the Application ID and Tenant ID (Step 1.5), and the app's permissions and admin consent (Steps 1.6 to 1.14). With a client secret, check that it hasn't expired. With a federated credential, check that you added it (Steps 2.9 to 2.12) to the same app registration whose Application ID you entered: the platform shows this message when that app has no federated credential at all, for example if you clicked Save before adding it. If the credential is there and matches, your organisation may restrict federated credentials: check with your Microsoft administrator.
- The federated credential couldn't be verified for this Azure China (21Vianet) tenant: use a client secret for this integration instead.
- Federated sign-in is unavailable right now or The connection couldn't be checked: nothing was saved. Try again shortly.
- Entra couldn't verify the federated token: please contact support.
- The federated credential for this email delivery provider couldn't be prepared: nothing was saved. This usually means the name is too long for a federated credential: use a shorter name, and contact support if it still happens.
- Error (on its own): something went wrong while saving. Reload the page and check whether the integration was saved. If it wasn't, try again, and contact support if it keeps happening.
Comments
0 comments
Please sign in to leave a comment.