Send mail as an application for a user mailbox
- There is a java and a python demo (you can choose)
- Open Azure Active Directory in the Azure Portal
- Click on
App Registrations
- Add a new App Registration by clicking on
New Registration
- Give it a name (f.e. graphsendmail)
- Select
Accounts in this organizational directory only (Single tenant)
- Click on register
- You should now see your App Registration (if not please go to app registrations and then select it by name)
- ?????? Allow public client flows ??????
- Memorize the Application (client) ID
- Go to
Certificates & secrets
and add aNew client secret
- Memorize the client secret
- Go to
API permissions
and click onAdd a permission
- Click on
Microsoft Graph
- Click on
Application permissions
- Select
Mail.Send
- Click on
Add permissions
- Click on
- Click on
Grant Admin Consent
(This will give the application access to send mails on behalf of all users, that we will limit later to specific mailboxes.) - Configure an applcation (choose either java or python)
- For Java add client id, client secret and a mailbox upn to the application.properties file
- For Python add to the python config.py file
- Go to Exchange Admin Center
- Click on
Groups
(UnderRecipients
) - Click on
Add a group
- Select
Mail-enabled security
and click onNext
- Give it a name (f.e. graphsendmailgroup) and click on
Next
- Add an owner
- Add here the mailboxes as members, that you would like to use with your applicaton.
- Use the name as group mail address and memorize the mail address of the group
- Click on
Create
- Select
- Run the following script to create an application policy
# connect to exchange online Connect-ExchangeOnline # add a new application policy (take the memorized data) New-ApplicationAccessPolicy -AppId ClientAppId -PolicyScopeGroupId mailEnabledSecurityGroupName@domain -AccessRight RestrictAccess -Description "Restrict this app to members of distribution group EvenUsers." # test if the application can use a mailbox (that is member of the group) Test-ApplicationAccessPolicy -Identity mailbox@domain -AppId ClientAppId
- Go into the directory of the application (choose either java or python)
- For Java go to java directory
- For Python go to python directory