Skip to content

Instantly share code, notes, and snippets.

@amiller
Created February 10, 2026 01:57
Show Gist options
  • Select an option

  • Save amiller/59c8a6a617386f60fc9c9336ca10aabe to your computer and use it in GitHub Desktop.

Select an option

Save amiller/59c8a6a617386f60fc9c9336ca10aabe to your computer and use it in GitHub Desktop.
OAuth3 Demo: Microsoft Email Fetch (read-only, 5 messages)
// @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