Source: https://cli.nylas.com/guides/office365-email-powershell

Guide

# Office 365 Email from PowerShell

This guide is about one Microsoft-specific pain point: replacing Azure app registration, tenant admin consent, and Microsoft Graph PowerShell plumbing with a shorter Office 365 workflow. It shows how to authenticate, list, search, read, and send O365 mail from PowerShell without building a Graph app first.

Written by [Nick Barraclough](https://cli.nylas.com/authors/nick-barraclough) • Product Manager

Reviewed by [Hazik](https://cli.nylas.com/authors/hazik)

Updated April 16, 2026

Verified

 —

CLI

3.1.1

 ·

Outlook, Microsoft 365

 ·

last tested

April 11, 2026

> **TL;DR:** Skip Azure app registration, Graph API modules, and tenant-consent friction. Run `nylas auth login` once, then use `nylas email list`, `nylas email send`, and `nylas email search` directly from PowerShell.

## The Microsoft Graph API problem

Here is what it takes to send a single email with Microsoft Graph from PowerShell:

```powershell
# Microsoft Graph API approach — 20+ lines to send one email

# Step 1: Register an app in Azure Portal (manual, ~10 minutes)
# Step 2: Get tenant admin to consent to Mail.Send permission
# Step 3: Install the Graph module
Install-Module Microsoft.Graph -Scope CurrentUser

# Step 4: Authenticate with specific scopes
Connect-MgGraph -Scopes "Mail.ReadWrite", "Mail.Send"

# Step 5: Build the message object
$message = @{
    Subject = "Weekly Report"
    Body = @{
        ContentType = "HTML"
        Content = "<h1>Report</h1><p>See attached.</p>"
    }
    ToRecipients = @(
        @{
            EmailAddress = @{
                Address = "alice@company.com"
            }
        }
    )
}

# Step 6: Send
Send-MgUserMessage -UserId "me" -BodyParameter @{ Message = $message }

# That is 6 steps and ~20 lines for one email.
```

Now here is the same thing with Nylas CLI:

```powershell
# Nylas CLI approach — 1 line
nylas email send `
    --to "alice@company.com" `
    --subject "Weekly Report" `
    --body-html "<h1>Report</h1><p>See attached.</p>" `
    --yes
```

## Authenticate your Office 365 account

```powershell
# Install Nylas CLI (one-liner for PowerShell)
irm https://cli.nylas.com/install.ps1 | iex

# Or install with Go (requires Go 1.21+)
# go install github.com/nylas/cli/cmd/nylas@latest

# Authenticate — opens browser for Microsoft OAuth
nylas auth login

# Verify your account is connected
nylas auth whoami
```

That is it. No Azure portal, no app registration, no client secrets, no tenant admin consent. The CLI handles the OAuth flow with Microsoft's identity platform and stores tokens securely.

## List Office 365 email

```powershell
# Graph API: List messages
# Connect-MgGraph -Scopes "Mail.Read"
# Get-MgUserMessage -UserId "me" -Top 10 |
#     Select-Object Subject, From, ReceivedDateTime

# Nylas CLI: List messages
nylas email list --limit 10
```

Get JSON output for scripting:

```powershell
# List emails as PowerShell objects
$emails = nylas email list --json --limit 20 | ConvertFrom-Json

# Display subject and sender
$emails | ForEach-Object {
    Write-Host "$($_.from[0].name): $($_.subject)"
}

# Filter to unread
$unread = nylas email list --json --unread --limit 50 | ConvertFrom-Json
Write-Host "You have $($unread.Count) unread messages"
```

## Search Office 365 email

```powershell
# Graph API: Search messages
# Get-MgUserMessage -UserId "me" -Filter "contains(subject, 'quarterly report')"
# # Or use the Search API with KQL syntax...
# # which requires different permissions and a different endpoint

# Nylas CLI: Search messages
nylas email search "quarterly report" --json --limit 20 | ConvertFrom-Json

# Search by sender
nylas email search "from:cfo@company.com" --json --limit 10 | ConvertFrom-Json

# Search with date range
nylas email search "budget 2026" --json --limit 30 | ConvertFrom-Json
```

## Read a specific email

```powershell
# Graph API: Read a message
# Get-MgUserMessage -UserId "me" -MessageId $msgId |
#     Select-Object Subject, Body, From, ToRecipients

# Nylas CLI: Read a message
nylas email read msg_abc123def --json | ConvertFrom-Json

# Get the message ID from a list, then read it
$latest = nylas email list --json --limit 1 | ConvertFrom-Json
$full = nylas email read $latest[0].id --json | ConvertFrom-Json
Write-Host "Subject: $($full.subject)"
Write-Host "Body: $($full.body)"
Write-Host "From: $($full.from[0].email)"
```

## Send email from Office 365

```powershell
# Simple text email
nylas email send `
    --to "alice@company.com" `
    --subject "Meeting notes" `
    --body "Here are the notes from today's standup." `
    --yes

# HTML email
nylas email send `
    --to "team@company.com" `
    --subject "Sprint Summary" `
    --body-html "<h2>Sprint 14</h2><p>Completed 23 story points.</p>" `
    --yes

# Multiple recipients
nylas email send `
    --to "alice@company.com,bob@company.com" `
    --subject "Action items" `
    --body "Please review the attached proposal by Friday." `
    --yes
```

## Manage email folders

```powershell
# List emails in a specific folder
nylas email list --json --folder "inbox" --limit 20 | ConvertFrom-Json
nylas email list --json --folder "sent" --limit 20 | ConvertFrom-Json
nylas email list --json --folder "drafts" --limit 10 | ConvertFrom-Json

# List only emails with attachments
nylas email list --json --has-attachment --limit 20 | ConvertFrom-Json

# Combine filters
$inboxUnread = nylas email list --json `
    --folder "inbox" `
    --unread `
    --limit 50 | ConvertFrom-Json
Write-Host "$($inboxUnread.Count) unread messages in inbox"
```

## Side-by-side comparison

Here is how common tasks compare between Microsoft Graph PowerShell and Nylas CLI:

### List recent emails

```powershell
# Microsoft Graph (requires Install-Module, Connect-MgGraph, Mail.Read scope)
Install-Module Microsoft.Graph.Mail -Scope CurrentUser
Connect-MgGraph -Scopes "Mail.Read"
$messages = Get-MgUserMessage -UserId "me" -Top 10
$messages | Select-Object Subject, @{N="From";E={$_.From.EmailAddress.Address}}, ReceivedDateTime

# Nylas CLI (requires: nylas auth login)
nylas email list --limit 10
```

### Search for emails

```powershell
# Microsoft Graph
$filter = "contains(subject, 'invoice')"
Get-MgUserMessage -UserId "me" -Filter $filter -Top 20

# Nylas CLI
nylas email search "invoice" --limit 20
```

### Send an email

```powershell
# Microsoft Graph (12 lines)
$params = @{
    Message = @{
        Subject = "Hello"
        Body = @{
            ContentType = "Text"
            Content = "Meeting at 3 PM."
        }
        ToRecipients = @(
            @{ EmailAddress = @{ Address = "alice@company.com" } }
        )
    }
}
Send-MgUserMessage -UserId "me" -BodyParameter $params

# Nylas CLI (1 line)
nylas email send --to "alice@company.com" --subject "Hello" --body "Meeting at 3 PM." --yes
```

### Read a specific message

```powershell
# Microsoft Graph
$msg = Get-MgUserMessage -UserId "me" -MessageId $id
$msg.Body.Content

# Nylas CLI
nylas email read $id --json | ConvertFrom-Json | Select-Object -ExpandProperty body
```

## Scripting workflows

Because Nylas CLI outputs JSON, it integrates naturally into PowerShell scripts. Here is a complete workflow that processes O365 email:

```powershell
# o365-inbox-processor.ps1
# Process unread emails and take action based on sender/subject

$unread = nylas email list --json --unread --limit 100 | ConvertFrom-Json

foreach ($email in $unread) {
    $sender = $email.from[0].email
    $subject = $email.subject

    # Auto-categorize
    switch -Regex ($subject) {
        "invoice|receipt|payment" {
            Write-Host "[FINANCE] $sender — $subject"
        }
        "deploy|release|hotfix" {
            Write-Host "[DEVOPS]  $sender — $subject"
        }
        "meeting|calendar|invite" {
            Write-Host "[MEETING] $sender — $subject"
        }
        default {
            Write-Host "[OTHER]   $sender — $subject"
        }
    }
}

# Summary
$byCategory = $unread |
    Group-Object -Property {
        switch -Regex ($_.subject) {
            "invoice|receipt|payment" { "Finance" }
            "deploy|release|hotfix"   { "DevOps" }
            "meeting|calendar|invite" { "Meeting" }
            default                    { "Other" }
        }
    }

Write-Host "`nSummary:"
$byCategory | ForEach-Object {
    Write-Host "  $($_.Name): $($_.Count) emails"
}
```

## Multiple accounts

If you have multiple O365 accounts (or a mix of O365 and Gmail), authenticate each one and switch between them:

```powershell
# Authenticate work and personal accounts
nylas auth login   # Work O365 account
nylas auth login   # Personal Gmail account

# Verify current account
nylas auth whoami

# Use --grant to target a specific account
nylas email list --json --grant work@company.com --limit 10 | ConvertFrom-Json
nylas email list --json --grant personal@gmail.com --limit 10 | ConvertFrom-Json

# Send from a specific account
nylas email send `
    --grant work@company.com `
    --to "client@example.com" `
    --subject "Proposal" `
    --body "Please find the proposal attached." `
    --yes
```

## Frequently asked questions

### Do I need an Azure app registration to use Nylas CLI with Office 365?

No. Nylas CLI handles OAuth and app registration for you. Run `nylas auth login`, select your Microsoft account, and you are authenticated. No Azure portal, no client IDs, no tenant admin consent required.

### Can Nylas CLI access shared mailboxes in Office 365?

Yes. After authenticating your primary account with `nylas auth login`, you can access shared mailboxes that your account has permissions to. Authenticate the shared mailbox as a separate grant with `nylas auth login` and use `--grant` to target it.

### Does Nylas CLI work with Microsoft 365 Government (GCC)?

Nylas CLI supports standard Microsoft 365 and Office 365 plans. For government cloud (GCC/GCC High) environments, check the Nylas documentation for current support status as these environments have separate authentication endpoints.

### Can I use the same scripts for Gmail and Office 365?

Yes. Nylas CLI abstracts provider differences. The same commands -- `nylas email list`, `nylas email send`, `nylas email search` -- work identically whether your account is Gmail, Office 365, Exchange, Yahoo, iCloud, or any IMAP provider. Authenticate each account with `nylas auth login` and use `--grant` to switch between them.

---

## Next steps

- [Read and search email in PowerShell](https://cli.nylas.com/guides/read-email-powershell) -- list unread, search by sender, export to CSV
- [Download email attachments in PowerShell](https://cli.nylas.com/guides/download-attachments-powershell) -- filter by type, batch download, rename
- [Email and calendar automation in PowerShell](https://cli.nylas.com/guides/email-calendar-powershell) -- availability checks, event creation, reminders
- [PowerShell email monitoring and alerts](https://cli.nylas.com/guides/powershell-email-monitoring) -- disk space, service health, uptime notifications
- [PowerShell email in CI/CD pipelines](https://cli.nylas.com/guides/powershell-email-cicd) -- build notifications, deploy alerts, test results
- [Automated email reports with PowerShell](https://cli.nylas.com/guides/powershell-email-reports) -- CSV reports, scheduled sends, templates
- [Replace Send-MgUserMessage](https://cli.nylas.com/guides/replace-send-mgusermessage) -- migrating from Graph PowerShell cmdlets
- [List Outlook emails from the command line](https://cli.nylas.com/guides/list-outlook-emails) -- the bash version of O365 email access
- [Send email from the terminal](https://cli.nylas.com/guides/send-email-from-terminal) -- cross-platform email sending guide
- [Full command reference](https://cli.nylas.com/docs/commands) -- every flag and subcommand
