Configure M365 Graph Api
It's recommended to use Graph API for M365 instead of SMTP username and app password. Moreover it's more easy to configure than to create app password in some cases.
1. Register new application
To create a Tenant ID, Client ID, and Secret Key, go to the Microsoft Azure and register a new application.
Microsoft Azure > Azure services > App registrations > New registration
Fill out the form and click the "Register" button
- Name: Oxilayer Invoice app
- Supported account types: Accounts in this organizational directory only (* only - Single tenant)
- Redirect URI (optional): leave blank

2. Copy Tenant ID and Client ID
After you register the new application, you will be redirected to the app's home page, where you can find your Client ID (1) and Tenant ID (2).

3. Create a secret key
The next step is to create a secret key. Go to:
Manage > Certificates & secrets > + New client secret
Fill out the form using the following data, and click the "Add" button.
- Description: Oxilayer Invoice app
- Expires: 730 days

After that, it will generate a "Secret ID". Copy the value (1).

4. Add app permissions
Lastly, there is a need to add app permissions and allow this app to send emails. Go to:
1. Manage (1) > API permissions (2) > + Add a permission (3)

2. Microsoft Graph (1) > Application permissions (2).
3. In the search box, enter "Mail.Send" (3) and select "Mail.Send" (4) permissions.
4. Click on the "Add permissions" (5) button

Finally click on the "Grant admin consent for Company Name" (1).
