2025-05-28 18:27:10 +02:00

33 lines
899 B
Python
Executable File

import asyncio
from msgraph.core import GraphClient
from azure.identity import DeviceCodeCredential
# Reemplaza con tu CLIENT_ID
credential = DeviceCodeCredential(
client_id="b8d7f3bf-e9a7-4352-b379-833e99a79733"
)
scopes = ['Mail.Read']
graph_client = GraphClient(credential=credential, scopes=scopes)
async def get_mail():
response = await graph_client.get(
'/me/messages',
params={
'$select': 'sender,subject',
'$filter': 'isRead eq false'
}
)
if response.status_code == 200:
mail = response.json()
for message in mail.get('value', []):
sender = message['sender']['emailAddress']['address']
subject = message['subject']
print(f"De: {sender}, Asunto: {subject}")
else:
print(f"Error: {response.status_code}")
print(response.json())
asyncio.run(get_mail())