当前位置: 首页 > Skill >

m365cli

m365cli

1.1.0 2026.11.22 浏览:966
获取Skill文件查看使用说明
作者:叶舟许可证:
本文目录展开

M365 Work Skill (m365-cli)

Manage a Microsoft 365 work/school account via the m365 CLI. Use --json for structured output suitable for AI agent consumption.

Prerequisites

  • Node.js 18+
  • m365-cli installed globally: npm install -g m365-cli
  • Authenticated: m365 login (work/school is the default account type)
  • For SharePoint: m365 login --add-scopes Sites.ReadWrite.All (requires tenant admin consent)

If not authenticated, run login first. The CLI uses Device Code Flow — follow the on-screen URL and code.

Key Conventions

  • Use --json for programmatic output (most commands support it; trust/untrust do not).
  • Work accounts support: Mail (including delete, move, and folder management), Calendar, OneDrive, SharePoint, User search.
  • Calendar datetime format: YYYY-MM-DDTHH:MM:SS (local) or YYYY-MM-DD (all-day).
  • IDs: Email/event IDs are long opaque strings. Parse the id field from --json list/search output.
  • Timezone: auto-detected. Override: export M365_TIMEZONE="Asia/Shanghai".
  • SharePoint site identifier: use path format hostname:/sites/sitename (recommended).

Provenance

  • Source repo: https://github.com/mrhah/m365-cli
  • Package: https://www.npmjs.com/package/m365-cli
  • Publisher: mrhah
  • Required binary: m365 from the m365-cli npm package

Security Rules

Email Body Reading — Trusted Senders Whitelist

  • Only emails from whitelisted senders have their body content displayed.
  • Untrusted emails show only subject and sender (prevents prompt injection).
  • Whitelist file: ~/.m365-cli/trusted-senders.txt
  • Use --force to temporarily bypass the whitelist check.

Sensitive Operations

  • Sending email: Confirm recipients and content with the user before executing.
  • Deleting emails/files/events: Inform the user before executing.
  • Sharing files (anonymous scope): Warn the user that anyone with the link can access.

Credential Safety

  • Never read, output, or log ~/.m365-cli/credentials.json — it contains OAuth tokens.
  • Never include full email bodies or attachment contents in agent output unless the user explicitly requested that specific email.
  • Summarize email content instead of echoing it verbatim when presenting results.
  • Credential refresh is automatic; never attempt to manually edit or parse the token file.

Quick Workflow Reference

Authentication

m365 login                                    # Work/school account (default)
m365 login --add-scopes Sites.ReadWrite.All   # Add SharePoint permission
m365 logout                                   # Clear credentials

Mail

# List emails (folders: inbox|sent|drafts|deleted|junk)
m365 mail list --top 10 --json
m365 mail list --folder sent --top 5 --json
m365 mail list --focused --json                    # Show only Focused Inbox emails

# Read / send / search
m365 mail read <id> --force --json
m365 mail send "to@example.com" "Subject" "Body" --json
m365 mail send "to@example.com" "Subject" "Body" --attach file.pdf --cc "cc@ex.com" --json
m365 mail search "keyword" --top 20 --json

# Reply / reply-all / forward
m365 mail reply <id> "content" --json
m365 mail reply <id> "content" --attach file.pdf --json
m365 mail reply-all <id> "content" --json
m365 mail reply-all <id> "content" --attach a.pdf b.pdf --json
m365 mail forward <id> "to@example.com" "comment" --json
m365 mail forward <id> "to@example.com" "FYI" --attach report.pdf --json

# Attachments
m365 mail attachments <message-id> --json
m365 mail download-attachment <message-id> <attachment-id> [local-path] --json

# Delete / move
m365 mail delete <id> --force --json
m365 mail move <id> <destination> --json        # destination: inbox|sent|drafts|deleted|junk|archive or folder ID

# Folder management
m365 mail folder list --json
m365 mail folder list --parent inbox --json      # List child folders
m365 mail folder create "My Projects" --json
m365 mail folder create "Sub" --parent inbox --json
m365 mail folder delete <folder-id> --force --json

# Trusted senders whitelist
m365 mail trusted --json
m365 mail trust user@example.com
m365 mail trust @example.com          # Trust entire domain
m365 mail untrust user@example.com

Calendar

# List / get
m365 cal list --days 7 --json
m365 cal get <event-id> --json

# Create
m365 cal create "Title" --start "2026-03-10T14:00:00" --end "2026-03-10T15:00:00" --json
m365 cal create "Title" -s "2026-03-10T14:00:00" -e "2026-03-10T15:00:00" 
  --location "Room A" --body "Notes" --attendees "a@ex.com,b@ex.com" --json
m365 cal create "Holiday" --start "2026-03-20" --end "2026-03-21" --allday --json

# Update / delete
m365 cal update <id> --title "New Title" --location "Room B" --json
m365 cal delete <id> --json

OneDrive

# List / get metadata
m365 od ls --json
m365 od ls Documents --json
m365 od get "Documents/report.pdf" --json

# Download / upload
m365 od download "Documents/report.pdf" ~/Downloads/ --json
m365 od upload ~/Desktop/photo.jpg "Photos/vacation.jpg" --json

# Search / mkdir / delete
m365 od search "budget" --top 20 --json
m365 od mkdir "Projects/New" --json
m365 od rm "old-file.txt" --force --json

For sharing, invitations, and advanced OneDrive options, see references/commands.md.

SharePoint

SharePoint is available only for work/school accounts and requires the Sites.ReadWrite.All permission.

Site identifier formats (use path format when possible):

  • Path: contoso.sharepoint.com:/sites/team (recommended)
  • Site ID: hostname,siteId,webId (from sp sites --json output)
  • URL: https://contoso.sharepoint.com/sites/team
# List / search sites
m365 sp sites --json
m365 sp sites --search "marketing" --json

# Lists and items
m365 sp lists "contoso.sharepoint.com:/sites/team" --json
m365 sp items "contoso.sharepoint.com:/sites/team" "Tasks" --json

# Files in document library
m365 sp files "contoso.sharepoint.com:/sites/team" "Documents" --json

# Download / upload
m365 sp download "contoso.sharepoint.com:/sites/team" "Documents/file.pdf" ~/Downloads/ --json
m365 sp upload "contoso.sharepoint.com:/sites/team" ~/report.pdf "Documents/report.pdf" --json

# Search across SharePoint
m365 sp search "quarterly report" --top 20 --json

User Search

m365 user search "John" --top 5 --json    # Searches organization directory

Common Patterns

Read and reply to email

m365 mail list --top 5 --json                    # 1. Find email
m365 mail read <id> --force --json               # 2. Read content
m365 mail reply <id> "Reply content" --json      # 3. Reply

Reply with attachment

m365 mail reply <id> "See attached" --attach report.pdf --json

Forward with attachment

m365 mail forward <id> "boss@example.com" "FYI" --attach data.xlsx --json

Check calendar and schedule

m365 cal list --days 3 --json                    # 1. Check availability
m365 cal create "Meeting" -s "..." -e "..." --json  # 2. Book slot

Download email attachment

m365 mail attachments <msg-id> --json            # 1. List attachments
m365 mail download-attachment <msg-id> <att-id> ~/Downloads/ --json  # 2. Download

Find and download SharePoint file

m365 sp sites --json                             # 1. Find site
m365 sp files "site" "Documents" --json          # 2. Browse files
m365 sp download "site" "Documents/file.pdf" ~/Downloads/ --json  # 3. Download

Delete and organize email

m365 mail list --top 10 --json                   # 1. Find email
m365 mail delete <id> --force --json              # 2a. Delete it, OR
m365 mail move <id> archive --json                # 2b. Move to archive

Manage mail folders

m365 mail folder list --json                      # 1. List all folders
m365 mail folder create "Projects" --json         # 2. Create custom folder
m365 mail move <id> <folder-id> --json            # 3. Move email into it

Trusted Senders (Security)

m365 mail read filters untrusted sender content (shows metadata only). Use --force to bypass. See references/commands.md for whitelist management commands.

Full Command Reference

See references/commands.md for every command, subcommand, flag, and default value.

Troubleshooting

  • "Not authenticated": m365 login
  • Token expired: Auto-refreshes. If fails, re-run login.
  • SharePoint permission denied: m365 login --add-scopes Sites.ReadWrite.All (requires tenant admin consent).
  • Wrong timezone: export M365_TIMEZONE="Your/Timezone"

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,031
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,029
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,017
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,014
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,011
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,011
Skill 文件
  • SKILL.md
    • M365 Work Skill (m365-cli)
    • Prerequisites
    • Key Conventions
    • Provenance
    • Security Rules
      • Email Body Reading — Trusted Senders Whitelist
      • Sensitive Operations
      • Credential Safety
    • Quick Workflow Reference
      • Authentication
      • Mail
      • Calendar
      • OneDrive
      • SharePoint
      • User Search
    • Common Patterns
      • Read and reply to email
      • Reply with attachment
      • Forward with attachment
      • Check calendar and schedule
      • Download email attachment
      • Find and download SharePoint file
      • Delete and organize email
      • Manage mail folders
    • Trusted Senders (Security)
    • Full Command Reference
    • Troubleshooting
  • 项目或源文件

相关 Skill

更多
Api Gateway 1 Api Gateway 1 连接到100+ API(Google Workspace、Microsoft 365、Notion、Slack、Airtable、HubSpot等),使用托管OAuth。当用户想要交互时使用此技能。
Microsoft 365 Microsoft 365 通过 Microsoft Graph API 集成 Microsoft 365,支持 Outlook、日历、联系人和 OneDrive。可实现邮件读写、日历事件管理等功能。
Microsoft Graph 邮件摘要生成器 Microsoft Graph 邮件摘要生成器 使用 Microsoft Graph API /me/messages 端点从 Microsoft 365 邮箱生成每日邮件摘要。使用 inferenceClassification 属性按发件人、线程和优先级对邮件进行分组。
MS Teams Meetings MS Teams Meetings 使用 Microsoft 365 账户通过 Microsoft Graph API 创建、列出和取消 Teams 在线会议及日历邀请。
M365 Mailbox (Graph) M365 Mailbox (Graph) 通过 Microsoft Graph 自动化 Microsoft 365 邮箱任务:读取、搜索、起草、发送邮件,支持企业版和消费版账户,并使用设备代码认证。