ConnectOnionConnectOnion

Receive Emails

Check your inbox with one line. Process emails safely. Keep it simple.

Quick Start

10 seconds
quickstart.py
1from connectonion import get_emails 2 3# Get your emails 4emails = get_emails()

That's it. You have your emails.

Core Concept

Three functions. That's all:

core.py
1get_emails(last=10, unread=False) # Get emails 2send_email(to, subject, message) # Send email 3mark_read(email_id) # Mark as read after processing

Important: Emails are NOT auto-marked as read. You control when to mark them.

Setup

Set your email credentials:

Terminal
$export EMAIL_ADDRESS="you@example.com"
$export EMAIL_PASSWORD="your-app-password"
$export IMAP_SERVER="imap.gmail.com" # Optional, defaults to Gmail

Gmail users: Use an App Password, not your regular password.

Common Patterns

Check for new emails

check_new.py
1from connectonion import get_emails, mark_read 2 3# Get unread emails 4new_emails = get_emails(unread=True) 5 6for email in new_emails: 7 print(f"New from {email['from']}: {email['subject']}") 8 9 # Process the email 10 if process_email(email): 11 mark_read(email['id']) # Only mark if processed successfully

Get latest email

latest.py
1# Get just the most recent email 2emails = get_emails(last=1) 3if emails: 4 latest = emails[0] 5 print(f"Latest: {latest['subject']}")

Reply to emails

reply.py
1from connectonion import get_emails, send_email, mark_read 2 3# Check and reply pattern 4for email in get_emails(unread=True): 5 if "urgent" in email["subject"].lower(): 6 # Send reply 7 send_email( 8 email["from"], 9 f"Re: {email['subject']}", 10 "I'm on it!" 11 ) 12 # Mark as handled 13 mark_read(email['id'])

API Reference

get_emails(last=10, unread=False)

Fetch emails from your inbox.

last - Number of emails to fetch (default: 10)

unread - Only fetch unread emails (default: False)

Returns list of email dicts with: id, from, subject, date, body

mark_read(email_id)

Mark an email as read.

email_id - The email ID from get_emails()

mark_unread(email_id)

Mark an email as unread.

email_id - The email ID from get_emails()

Email Agent Example

email_agent.py
1from connectonion import Agent, get_emails, send_email, mark_read 2 3def check_inbox() -> str: 4 """Check inbox for new emails.""" 5 emails = get_emails(unread=True) 6 if not emails: 7 return "No new emails" 8 return f"Found {len(emails)} unread emails:\n" + "\n".join( 9 f"- {e['from']}: {e['subject']}" for e in emails 10 ) 11 12def reply_to_email(email_id: str, message: str) -> str: 13 """Reply to an email by ID.""" 14 emails = get_emails(last=50) 15 email = next((e for e in emails if e['id'] == email_id), None) 16 if not email: 17 return "Email not found" 18 19 send_email(email['from'], f"Re: {email['subject']}", message) 20 mark_read(email_id) 21 return f"Replied to {email['from']}" 22 23agent = Agent( 24 name="email-assistant", 25 tools=[check_inbox, reply_to_email], 26 system_prompt="You help manage emails. Check inbox and reply as needed." 27) 28 29agent.input("Check my inbox and summarize what's there")

get_emails vs Gmail

get_emails (IMAP)

  • Simple functions
  • Works with any email provider
  • Uses EMAIL_PASSWORD env var
  • Basic read/mark operations
  • Best for simple automation

Gmail (OAuth)

  • Full Gmail class with many methods
  • Gmail-specific features (labels, archive, star)
  • Uses co auth google
  • Search, CRM, contact analysis
  • Best for advanced Gmail automation

Need more features? Check out Gmail for full inbox management.