ConnectOnionConnectOnion
DocsMicrosoft Integration

Microsoft Integration

Send emails via Outlook and read calendar events from your AI agents. 30-second setup.

Quick Start

Terminal
$co auth microsoft

What happens:

  1. Opens browser to Microsoft OAuth consent screen
  2. You authorize Mail + Calendar permissions
  3. Credentials saved to .env (both local and global ~/.co/keys.env)
  4. Ready to use Outlook and Calendar tools immediately

That's it. Your agents can now send emails via Outlook and read your Microsoft calendar.

Prerequisites

Before running co auth microsoft, you must authenticate with OpenOnion:

Terminal
$co auth

This creates your OPENONION_API_KEY which is required for Microsoft OAuth to work.

What Gets Saved

After successful authentication, your .env file contains:

.env
1# Microsoft OAuth Credentials 2MICROSOFT_ACCESS_TOKEN=eyJ0eXAi... 3MICROSOFT_REFRESH_TOKEN=0.ATcA... 4MICROSOFT_TOKEN_EXPIRES_AT=2025-12-31T23:59:59 5MICROSOFT_SCOPES=Mail.Read,Mail.Send,Calendars.Read,Calendars.ReadWrite 6MICROSOFT_EMAIL=your.email@outlook.com

Security notes

  • Credentials are saved to both local .env and ~/.co/keys.env
  • File permissions set to 0600 (read/write for owner only) on Unix systems
  • Access tokens expire, but refresh tokens allow automatic renewal
  • You can revoke access anytime via Microsoft Account settings

Permissions Requested

When you run co auth microsoft, we request these Microsoft Graph API scopes:

ScopePurposeWhat agents can do
Mail.ReadRead user emailsRead inbox, search emails
Mail.SendSend emails on your behalfSend emails via Outlook
Calendars.ReadRead calendar eventsRead your calendar to check availability
Calendars.ReadWriteCreate/modify eventsCreate and update calendar events
User.ReadGet your profileIdentify which Microsoft account is connected

Privacy First

We only request the permissions needed. We cannot:

  • Delete your emails
  • Access your OneDrive or other services
  • Access your contacts beyond basic profile

Using Microsoft OAuth in Agents

Once authenticated, your agents can use Microsoft-powered tools:

Send Email via Outlook

outlook_agent.py
1from connectonion import Agent, Outlook 2 3outlook = Outlook() 4 5agent = Agent( 6 "Outlook Assistant", 7 tools=[outlook] 8) 9 10agent.input("Send an email to alice@example.com saying hello")

Read Calendar Events

calendar_agent.py
1from connectonion import Agent, MicrosoftCalendar 2 3calendar = MicrosoftCalendar() 4 5agent = Agent( 6 "Calendar Assistant", 7 tools=[calendar] 8) 9 10agent.input("What's on my calendar this week?")

Outlook Tool Methods

The Outlook tool provides these capabilities:

outlook_methods.py
1from connectonion import Outlook 2 3outlook = Outlook() 4 5# Reading emails 6outlook.read_inbox(last=10, unread=False) # Get recent inbox emails 7outlook.get_sent_emails(max_results=10) # Get sent emails 8outlook.search_emails("quarterly report") # Search all emails 9outlook.get_email_body(email_id) # Get full email content 10 11# Sending emails 12outlook.send(to="alice@example.com", subject="Hello", body="Hi there!") 13outlook.send(to="alice@example.com", subject="Hello", body="Hi!", cc="bob@example.com") 14outlook.reply(email_id, body="Thanks for your message") 15 16# Actions 17outlook.mark_read(email_id) # Mark email as read 18outlook.mark_unread(email_id) # Mark email as unread 19outlook.archive_email(email_id) # Move to archive folder 20 21# Stats 22outlook.count_unread() # Count unread emails in inbox 23outlook.get_my_email() # Get connected Microsoft email address

Microsoft Calendar Tool Methods

The MicrosoftCalendar tool provides:

calendar_methods.py
1from connectonion import MicrosoftCalendar 2 3calendar = MicrosoftCalendar() 4 5# Reading events 6calendar.list_events(days_ahead=7, max_results=20) # Get upcoming events 7calendar.get_today_events() # Get today's events 8calendar.get_event(event_id) # Get event details 9 10# Creating events 11calendar.create_event( 12 title="Team Meeting", 13 start_time="2025-01-15 14:00", 14 end_time="2025-01-15 15:00", 15 description="Weekly sync", 16 attendees="alice@example.com,bob@example.com", 17 location="Conference Room A" 18) 19 20# Create Teams meeting (with auto-generated meeting link) 21calendar.create_teams_meeting( 22 title="Project Sync", 23 start_time="2025-01-15 14:00", 24 end_time="2025-01-15 15:00", 25 attendees="alice@example.com,bob@example.com" 26) 27 28# Updating & deleting 29calendar.update_event(event_id, title="Updated Title") 30calendar.delete_event(event_id) 31 32# Meetings & availability 33calendar.get_upcoming_meetings(days_ahead=7) # Get events with attendees 34calendar.find_free_slots("2025-01-15", duration_minutes=60) # Find free time 35calendar.check_availability("2025-01-15 14:00") # Check if specific time is free

Troubleshooting

"Not authenticated with OpenOnion"

You need to run co auth first to get your OPENONION_API_KEY:

Terminal
$co auth
$co auth microsoft

Authorization Timeout

If the browser window doesn't complete authorization within 5 minutes:

Terminal
$co auth microsoft

The command polls the backend every 5 seconds waiting for your authorization.

Credentials Not Working

Check if credentials are properly saved:

terminal
1# Check local .env 2cat .env | grep MICROSOFT_ 3 4# Check global keys 5cat ~/.co/keys.env | grep MICROSOFT_

If credentials exist but don't work, re-authenticate:

Terminal
$co auth microsoft

Revoke Access

To disconnect your Microsoft account:

Google vs Microsoft

Both integrations follow the same CLI pattern:

FeatureGoogleMicrosoft
Commandco auth googleco auth microsoft
EmailGmailOutlook
CalendarGoogle CalendarMicrosoft Calendar
APIGoogle APIsMicrosoft Graph API