Created
February 10, 2026 01:57
-
-
Save amiller/59c8a6a617386f60fc9c9336ca10aabe to your computer and use it in GitHub Desktop.
OAuth3 Demo: Microsoft Email Fetch (read-only, 5 messages)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @skill Microsoft Email Fetch | |
| // @description Fetch recent emails from Microsoft Graph API (read-only, limited to 5 messages) | |
| // @secrets MICROSOFT_API_KEY | |
| // @network graph.microsoft.com | |
| // @timeout 30 | |
| const MICROSOFT_API_KEY = Deno.env.get("MICROSOFT_API_KEY"); | |
| if (!MICROSOFT_API_KEY) { | |
| console.error("Error: MICROSOFT_API_KEY required"); | |
| Deno.exit(1); | |
| } | |
| console.log("π§ Fetching recent emails from Microsoft Graph API..."); | |
| console.log(`π API key configured (length: ${MICROSOFT_API_KEY.length})`); | |
| try { | |
| const response = await fetch("https://graph.microsoft.com/v1.0/me/messages?$top=5&$select=subject,from,receivedDateTime", { | |
| method: "GET", | |
| headers: { | |
| "Authorization": `Bearer ${MICROSOFT_API_KEY}`, | |
| "Content-Type": "application/json", | |
| }, | |
| }); | |
| if (!response.ok) { | |
| const error = await response.text(); | |
| console.error(`β API Error ${response.status}: ${error}`); | |
| Deno.exit(1); | |
| } | |
| const data = await response.json(); | |
| console.log(`\nβ Found ${data.value.length} recent emails:\n`); | |
| for (const email of data.value) { | |
| const from = email.from?.emailAddress?.name || email.from?.emailAddress?.address || 'Unknown'; | |
| const date = new Date(email.receivedDateTime).toLocaleString(); | |
| console.log(`π¬ ${email.subject}`); | |
| console.log(` From: ${from}`); | |
| console.log(` Date: ${date}\n`); | |
| } | |
| console.log(`\nπ Total emails fetched: ${data.value.length}`); | |
| } catch (error) { | |
| console.error(`Network error: ${error.message}`); | |
| Deno.exit(1); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment