Mail Configuration
VoIP Detective requires an external email server in order to send reports, alerts, and administrator emails out. To that end, VoIP Detective can use the following to send email:
- SMTP (including basic authentication and STARTTLS)
- Microsoft 365 OAuth2. VoIP Detective supports both Device code flow and Client credentials flow
Mail can be configured by going to Administration -> Configuration.
Under the Mail settings section, you can enter information relevant to your configuration.
Configuring SMTP

To configure SMTP for email delivery, do the following:
- Go to Administration -> Configuration
- Scroll down to the "Mail Settings" section
- Set Mail enable / disable to "enabled" and press the go button
- Set Mail Transport to SMTP and press the go button
- Enter your SMTP host and press the go button
- Enter any other necessary information like username, password, etc.
- Once complete, press the "check the email system (send a test message)" button to verify things are working.
Microsoft 365 OAuth2: Which Microsoft 365 method should I use?
| Method | Use it when | How it signs in |
|---|---|---|
| Device code flow | Your organization allows device code flow. This is the simpler setup. | A person signs in once in a browser. |
| Client credentials flow | Your organization blocks device code flow, for example with the Microsoft-managed “Block device code flow” Conditional Access policy. | VoIP Detective signs in as an app, with an app ID and client secret. No user signs in. |
Both methods need outbound access only, to login.microsoftonline.com (port 443) and smtp.office365.com (port 587). Your VoIP Detective server does not need to be reachable from the internet.
Configuring Microsoft 365 OAuth2: Client Credentials Flow
Client credentials flow: VoIP Detective signs in to Microsoft 365 as an app, using an app ID and client secret, so no user has to sign in.
Prerequisites
- A Microsoft 365 administrator who can register apps, grant admin consent and run Exchange Online PowerShell
- A mailbox to send from. We recommend a dedicated mailbox, such as
voipdetective@yourdomain.com - Authenticated SMTP enabled on that mailbox
Step 1. Create a new app (entra.microsoft.com)
- Go to App registrations → New registration.

- Name it “VoIP Detective Mail”, choose single tenant, and leave the redirect address empty.
- Copy the Application (client) ID and the Directory (tenant) ID.
Step 2. Give it permission to send
- Go to API permissions → Add a permission → APIs my organization uses.
- Search for “Office 365 Exchange Online”.
- Choose Application permissions → SMTP.SendAsApp → Add permissions.

- Click Grant admin consent. The permission should show a green tick.
Step 3. Create the secret and get the Object ID
- Go to Certificates & secrets → New client secret. Enter a description such as “VoIP Detective mail” and an expiration that works for your organization.

- Copy the Value, not the Secret ID. It’s shown only once.
- Write down or add a calendar reminder of the date the secret expires. Email stops on that date until you create a new one.
- Go to Enterprise applications, open the same app and copy its Object ID. The Object ID on the App registration page is a different number and won’t work.
Step 4. Allow the app to use your mailbox (PowerShell)
Run these commands in PowerShell, replacing the values in angle brackets:
Install-Module -Name ExchangeOnlineManagement Connect-ExchangeOnline -UserPrincipalName admin@yourdomain.com New-ServicePrincipal -AppId <client ID> -ObjectId <Object ID from step 3> Add-MailboxPermission -Identity "mailbox@yourdomain.com" -User <Object ID from step 3> -AccessRights FullAccess Get-CASMailbox -Identity "mailbox@yourdomain.com" | fl SmtpClientAuthenticationDisabled
The result should be False. If it shows True, turn on Authenticated SMTP for that mailbox in the Microsoft 365 admin center.
Which value goes where:
| Value | Looks like | Used in |
|---|---|---|
| Application (client) ID | An ID with dashes | PowerShell -AppId, and VoIP Detective |
| Directory (tenant) ID | An ID with dashes | VoIP Detective |
| Object ID (Enterprise applications) | An ID with dashes | PowerShell -ObjectId and -User |
| Client secret Value | Letters and symbols, often with a ~ | VoIP Detective only. Never PowerShell. |
Step 5: Set up VoIP Detective
- Go to Administration → Configuration → Mail settings.
- Set Mail enable / disable to Enabled.
- Set Mail Transport to Microsoft 365 OAuth2 and click Go.
- Click Setup OAuth2 (or Reconfigure OAuth2).
- Under Sign-in method, choose Client credentials flow (app ID and client secret).
- Enter the Application (Client) ID, Directory (Tenant) ID, Client secret (Value) and Sending Email Address.
- Check the address under Send the test email to.
- Click Test and save.
VoIP Detective gets an access token from Microsoft and sends a test email. Your settings are saved only if both steps succeed. If either fails, nothing is saved and your current mail settings stay as they are.
Step 6: Verify
On Mail settings, click Check the email system (send a test message) and confirm the email arrives.
Renewing the client secret
- Before the secret expires, create a new one in Certificates & secrets (Step 3).
- In VoIP Detective, click Reconfigure OAuth2, enter the new secret and click Test and save.
Troubleshooting
| Message | What to check |
|---|---|
AADSTS7000215 (invalid client secret) | The secret Value was copied wrongly, or the Secret ID was used. Create a new secret and copy its Value. |
AADSTS7000222 (expired client secret) | The secret has expired. Create a new one. |
AADSTS700016 or AADSTS90002 | The Application (Client) ID or Directory (Tenant) ID is wrong. |
| “SMTP.SendAsApp is not in the token” | The permission is missing or admin consent was not granted (Step 2). |
535 5.7.3 Authentication unsuccessful | Step 4 is incomplete or used the wrong Object ID. New permissions can also take a while to apply, so wait and try again. |
535 5.7.139 mentioning SmtpClientAuthentication | Authenticated SMTP is disabled on the mailbox or the tenant. |
| “Cannot reach Microsoft login endpoint” | Outbound access to login.microsoftonline.com on port 443 is blocked. |
Security notes
- The client secret is stored on the VoIP Detective server in
/var/www/tokens, outside the web folder. - VoIP Detective never displays the secret after it is saved.
- The app is granted only the SMTP sending permission in Microsoft Entra.
Configuring Microsoft 365 OAuth2: Device Code Flow
Device code flow: A person signs in to Microsoft 365 once in a browser using a short code, and VoIP Detective then sends email as that user.
Prerequisites:
- Administrator access to your Microsoft 365 / Azure tenant
- VoIP Detective OS 4.x or later with PHPMailer installed (use the command line (CLI) menu option 5.5.2)
- A valid Microsoft 365 mailbox that will be used to send emails
Step 1: Register an Application in Azure Portal
- Go to https://portal.azure.com and sign in with your administrator account
- Navigate to Microsoft Entra ID → App registrations (Note: Azure Active Directory has been renamed to Microsoft Entra ID)
- Click New registration
- Configure the application:
- Name: Enter a descriptive name (e.g., "VoIP Detective Email")
- Supported account types: Select "Accounts in this organizational directory only"
- Redirect URI: Leave blank (not required for Device Code Flow)

- Click Register
- On the application overview page, copy and save:
- Application (client) ID
- Directory (tenant) ID
Step 2: Enable Public Client Flow
- In your application, click Authentication in the left sidebar
- Go to Settings
- Set Allow public client flows to Yes
- Click Save
Note: Your VoIP Detective server only needs outbound internet access. It does not need to be reachable from the internet.

Step 3: Configure API Permissions
- Click API permissions in the left sidebar
- Click Add a permission
- Select Microsoft Graph
- Select Delegated permissions
- Search for and add the following permissions:
offline_access- Allows the app to refresh tokens automaticallySMTP.Send- Allows sending emails via SMTP
- Click Add permissions
- Click Grant admin consent for [Your Organization] and confirm
Note: You must grant admin consent for the permissions to take effect. Look for the green checkmarks in the Status column.

Step 4: Enable SMTP AUTH for the Mailbox
- Go to the Microsoft 365 Admin Center
- Navigate to Users → Active users
- Select the user/mailbox that will send emails
- Click the Mail tab
- Under "Email apps", click Manage email apps
- Ensure Authenticated SMTP is enabled
- Click Save changes
Step 5: Install PHPMailer on VoIP Detective
- Connect to your VoIP Detective server via SSH or console
- Navigate to Option 5 (Configure) → Option 5.5 (Mail Services)
- Select Option 2 to install PHPMailer with Microsoft 365 OAuth2 support
- Wait for the installation to complete
This will install the required components to send mail with M365 OAuth2
Step 6: Configure VoIP Detective Email Settings
- Go to Administration -> Configuration -> Mail settings.
- Set Mail enable / disable to Enabled and click Go.
- Set Mail Transport to Microsoft 365 OAuth2 and click Go.
- Click Setup OAuth2.
Step 7: Generate OAuth2 Tokens
- Log in to VoIP Detective as an administrator
- Navigate to Admin → Microsoft 365 OAuth2 Setup (or go directly to
https://YOUR_SERVER/admin/m365_oauth_setup.php) - Under Sign-in method, choose Device code flow (sign in as a user).
- Enter your Azure application credentials:
- Application (Client) ID: From Step 1
- Directory (Tenant) ID: From Step 1
- Click Continue
- You will see a device code and a URL. On any device with internet access (phone, laptop, etc.):
- Open https://microsoft.com/devicelogin
- Enter the code displayed on the VoIP Detective page
- Sign in with the Microsoft 365 account that will send emails
- Review the permissions and click Accept
- The VoIP Detective page will automatically detect the successful authentication
- Enter the email address you authenticated with and click Save Configuration
Note: The Device Code Flow allows you to authenticate as long as you have outbound internet access. You can complete the Microsoft authentication step on any internet-connected device.
Step 8: Verify
On Mail settings, click “Check the email system (send a test message)” and confirm the email arrives.
Token Lifecycle and Maintenance
Understanding how OAuth2 tokens work will help you maintain your email configuration:
| Token Type | Lifetime | Auto-Renews? |
|---|---|---|
| Access Token | 60-90 minutes | Yes - automatically when sending email |
| Refresh Token | 90 days of inactivity | Yes - as long as emails are sent regularly |
Key Points:
- Access tokens are refreshed automatically by VoIP Detective when sending emails
- Refresh tokens remain valid as long as your system sends at least one email every 90 days
- If no emails are sent for 90+ days, you will need to re-run the OAuth2 setup (Step 7)
Troubleshooting
Error: "Allow public client flows" not enabled
- Go to Azure Portal → App registrations → Your App → Authentication
- Set "Allow public client flows" to Yes
- Save and try again
Authentication unsuccessful (535 5.7.3)
- Verify SMTP AUTH is enabled for the mailbox (Step 4)
- Ensure admin consent was granted for API permissions (Step 3)
- Confirm the email address matches the account used during OAuth2 setup
- Re-run the OAuth2 setup (Step 7) to generate new tokens
Device code expired
- The device code is valid for approximately 15 minutes
- If it expires before you complete authentication, simply refresh the page and start again
Token refresh failed
- This typically occurs after 90+ days of inactivity
- Re-run the OAuth2 setup (Step 7) to generate new tokens
Permission denied / Unauthorized
- Verify the SMTP.Send permission is added and admin consent is granted
- Ensure you're using a licensed Microsoft 365 mailbox (not a shared mailbox without a license)
- Check that "Allow public client flows" is enabled
Tokens directory permission error
- Run deployment menu option 5.5.2 again to recreate the directory with correct permissions
- Or manually fix:
sudo chown apache:apache /var/www/tokens && sudo chmod 750 /var/www/tokens
Security Notes
- OAuth2 tokens are stored securely outside the web root in
/var/www/tokens/ - Token files are protected with restrictive permissions (640)
- No client secret is required with the Device Code Flow, reducing credential exposure
- Only the Apache web server process can read the token files
Additional Resources
- Microsoft Announcement: Basic Auth Retirement
- Microsoft Documentation: OAuth for SMTP
- Microsoft Device Code Flow Documentation
Mail Configuration Troubleshooting
To verify your mail settings, go to Administration -> Troubleshooting and look for "Mail System Test" This will allow you to send a test mail and view detailed debugging information.


Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article