python-o365
python-o365 copied to clipboard
How to read shared Email ID mails
I have tried all way but not getting to read shared email ID. Could you please help.
from O365 import Account, MSOffice365Protocol , MSGraphProtocol
credentials = ('client ID', 'cllient Secret')
# the default protocol will be Microsoft Graph
# the default authentication method will be "on behalf of a user"
protocol = MSGraphProtocol(default_resource='[email protected]')
scopes_graph = protocol.get_scopes_for('mailbox_shared')
#scopes = ['https://graph.microsoft.com/Mail.ReadWrite', 'https://graph.microsoft.com/Mail.Send']
print ("1")
account = Account(credentials=credentials, protocol=protocol,auth_flow_type='credentials', tenant_id='tenent_ID')
print("2")
if account.authenticate():
print('Authenticated!')
# now account is accesing the [email protected] in every api call.
shared_mailbox_messages = account.mailbox().get_messages()
We have already created APP and provided read access to could of email ID who has access to shared email box
Getting below Error
1
2
Authenticated!
Client Error: 401 Client Error: Unauthorized for url: https://graph.microsoft.com/v1.0/users/[email protected]/messages?%24top=25 | Error Message: The token contains no permissions, or permissions can not be understood.
Traceback (most recent call last):
File "abcmail6.py", line 23, in
either you don't have access to '[email protected]' or you don't have the admin consent.