npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mneuhaus/ms365-mail

v1.0.0

Published

Microsoft 365 Email CLI - A lightweight, focused CLI tool for Microsoft Graph email operations

Readme

MS365-Mail - Microsoft 365 Email CLI

A lightweight, focused CLI tool for Microsoft Graph email operations built with Bun. Inspired by tools like gh and glab - simple, intuitive, and purpose-built for email management.

Features

  • 🔐 Easy Authentication: Device code flow for secure login
  • 📧 Email Operations: List, search, read, and manage emails
  • 📎 Attachment Handling: Download individual or all attachments
  • 📁 Folder Management: Browse and manage mail folders
  • 🎨 Multiple Output Formats: Table (default) and JSON output
  • Fast Performance: Built with Bun for lightning-fast startup
  • 🔧 Configurable: Customizable defaults and preferences

Installation

Prerequisites

  • Bun runtime installed
  • Microsoft 365 or Outlook.com account

Install Dependencies

cd ms365-mail
bun install

Build Executable (Optional)

bun run build

This creates a single binary ms365-mail file that can be moved to your PATH.

Quick Start

  1. Authenticate:

    bun run src/index.js auth login
  2. List recent emails:

    bun run src/index.js list
  3. Search emails:

    bun run src/index.js search "project update"
  4. View email details:

    bun run src/index.js show abc123def

Usage

Authentication Commands

# Login with device code flow
ms365-mail auth login

# Check authentication status
ms365-mail auth status

# Logout and clear credentials
ms365-mail auth logout

Email Management

# List recent emails (default: 20)
ms365-mail list

# List specific number of emails
ms365-mail list --count 50

# List unread emails only
ms365-mail list --unread

# List emails from specific sender
ms365-mail list --from [email protected]

# List emails from last 7 days
ms365-mail list --since 7d

# List emails with attachments
ms365-mail list --has-attachments

# List emails from specific folder
ms365-mail list --folder sent

Search Operations

# Search email content
ms365-mail search "keyword"

# Search in subject only
ms365-mail search --subject "meeting"

# Search with sender filter
ms365-mail search --from [email protected] "report"

# Search emails with attachments
ms365-mail search --has-attachments "invoice"

Email Details

# Show email content
ms365-mail show <email-id>

# Show with full headers
ms365-mail show <email-id> --headers

# Show raw email data
ms365-mail show <email-id> --raw

Attachment Operations

# List attachments for an email
ms365-mail attachments <email-id>

# Download all attachments
ms365-mail download <email-id>

# Download to specific directory
ms365-mail download <email-id> --output ./my-downloads

# Download specific attachment
ms365-mail download <email-id> "report.pdf"

Folder Operations

# List all mail folders
ms365-mail folders

# List emails from specific folder
ms365-mail list --folder "Project Updates"

Global Options

--format json       # Output as JSON instead of table
--no-color         # Disable colored output
--config <file>    # Use custom config file
--help             # Show help information
--version          # Show version number

Configuration

The CLI stores configuration in ~/.config/ms365-mail/config.json:

{
  "auth": {
    "tenant_id": "common",
    "client_id": "your-app-id"
  },
  "defaults": {
    "count": 20,
    "format": "table",
    "folder": "inbox"
  },
  "output": {
    "color": true,
    "date_format": "YYYY-MM-DD HH:mm"
  }
}

Time Filters

Support for relative time expressions:

  • 1h, 6h - Hours
  • 1d, 7d - Days
  • 1w, 2w - Weeks
  • 1m, 3m - Months

Examples

# Daily email check
ms365-mail list --unread --count 10

# Find emails from specific person with attachments
ms365-mail search --from "[email protected]" --has-attachments

# Download all attachments from an email
ms365-mail show abc123 | grep "ID:" | cut -d' ' -f2 | xargs ms365-mail download

# Check emails from last week in sent folder
ms365-mail list --folder sent --since 1w --count 50

# Search for invoices and export to JSON
ms365-mail search "invoice" --format json > invoices.json

Error Codes

  • 0 - Success
  • 1 - General error
  • 2 - Authentication required

Microsoft App Registration

For organizational use, you may need to register your own Azure AD application:

  1. Go to Azure Portal
  2. Navigate to Azure Active Directory > App registrations
  3. Create new registration with these settings:
    • Name: MG Email CLI
    • Supported account types: Accounts in any organizational directory and personal Microsoft accounts
    • Redirect URI: Public client/native (mobile & desktop) - http://localhost
  4. Under API permissions, add:
    • Mail.Read (Delegated)
    • Mail.ReadWrite (Delegated)
  5. Update your config with the new client_id

Development

Project Structure

ms365-mail/
├── src/
│   ├── commands/          # Individual command implementations
│   ├── lib/              # Core libraries (auth, graph client, config)
│   ├── utils/            # Utilities (formatters, parsers)
│   └── index.js          # Main CLI entry point
├── package.json
└── README.md

Running Tests

bun test

Building

# Development build
bun run dev

# Production build (single binary)
bun run build

Troubleshooting

Authentication Issues

  • Ensure you have internet connectivity
  • Try clearing credentials: ms365-mail auth logout then ms365-mail auth login
  • Check if your organization requires app approval

Permission Issues

  • Verify the required Microsoft Graph permissions are granted
  • Contact your IT administrator for organizational accounts

Performance Issues

  • Use --count to limit results for large mailboxes
  • Consider using date filters (--since) for recent emails only

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Support

For issues and feature requests, please create an issue on the GitHub repository.