Guide
Office 365 Email from PowerShell
Managing Office 365 email programmatically usually means wrestling with Microsoft Graph API: app registrations, tenant admin consent, complex OAuth flows, and dozens of PowerShell modules. Nylas CLI replaces all of that with simple commands that work the same for Office 365, Gmail, and every other provider. This guide shows how to authenticate, list, search, read, and send O365 email from PowerShell without touching Graph API.
The Microsoft Graph API problem
Here is what it takes to send a single email with Microsoft Graph from 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:
# Nylas CLI approach — 1 line
nylas email send `
--to "alice@company.com" `
--subject "Weekly Report" `
--body-html "<h1>Report</h1><p>See attached.</p>" `
--yesAuthenticate your Office 365 account
# 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 whoamiThat 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
# 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 10Get JSON output for scripting:
# 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
# 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-JsonRead a specific email
# 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
# 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." `
--yesManage email folders
# 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
# 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 10Search for emails
# Microsoft Graph
$filter = "contains(subject, 'invoice')"
Get-MgUserMessage -UserId "me" -Filter $filter -Top 20
# Nylas CLI
nylas email search "invoice" --limit 20Send an email
# 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." --yesRead a specific message
# Microsoft Graph
$msg = Get-MgUserMessage -UserId "me" -MessageId $id
$msg.Body.Content
# Nylas CLI
nylas email read $id --json | ConvertFrom-Json | Select-Object -ExpandProperty bodyScripting workflows
Because Nylas CLI outputs JSON, it integrates naturally into PowerShell scripts. Here is a complete workflow that processes O365 email:
# 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:
# 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." `
--yesFrequently 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, Yahoo, or any IMAP provider. Authenticate each account with nylas auth login and use --grant to switch between them.
Next steps
- Automated email reports with PowerShell -- build reporting workflows with Nylas CLI and PowerShell
- List Outlook emails from the command line -- the bash version of O365 email access
- Send email from the terminal -- cross-platform email sending guide
- Full command reference -- every flag and subcommand