Microsoft deprecated Send-MailMessage in PowerShell. The official docs now say "This cmdlet does not guarantee secure connections to SMTP servers" and recommend against using it. But thousands of production scripts still depend on it for alerts, reports, and automation.
The replacement options aren't great. Send-MgUserMessage requires Microsoft Graph SDK setup and Azure AD app registration. Raw System.Net.Mail.SmtpClient is also deprecated. Building OAuth2 token flows from scratch takes hours.
Nylas CLI gives you a one-line replacement that handles OAuth automatically for Gmail, Outlook, Exchange, Yahoo, iCloud, and IMAP. No SMTP config, no app passwords, no token refresh logic.
Before and after
Send-MailMessage (deprecated)
# Old way — deprecated, insecure, requires SMTP config
Send-MailMessage `
-From "you@company.com" `
-To "team@company.com" `
-Subject "Daily Report" `
-Body "See attached." `
-Attachments "report.csv" `
-SmtpServer "smtp.office365.com" `
-Port 587 `
-UseSsl `
-Credential (Get-Credential)
Nylas CLI (replacement)
# New way — OAuth, no SMTP, no credentials in scripts
nylas email send `
--to "team@company.com" `
--subject "Daily Report" `
--body "See attached." `
--attach "report.csv" `
--yes
No SMTP server. No port. No credentials stored in your script. OAuth2 tokens are managed by the CLI and refreshed automatically.
Install on Windows
# One-line install via PowerShell
irm https://cli.nylas.com/install.ps1 | iex
# Verify
nylas --version
For macOS/Linux, use brew install nylas/nylas-cli/nylas. Full install options in the getting started guide.
Authenticate once
nylas auth login
nylas auth whoami
# => Authenticated as you@company.com (Microsoft 365)
The CLI opens a browser for OAuth consent. After that, your scripts run unattended — no Get-Credential prompts, no stored passwords.
Migration examples
Simple notification email
# Before (Send-MailMessage)
Send-MailMessage -To "ops@company.com" -Subject "Build failed" `
-Body "CI pipeline failed at $(Get-Date)" -SmtpServer "smtp.gmail.com"
# After (Nylas CLI)
nylas email send --to "ops@company.com" `
--subject "Build failed" `
--body "CI pipeline failed at $(Get-Date)" --yes
Email with attachment
# Before
Send-MailMessage -To "finance@company.com" -Subject "Monthly Report" `
-Body "Report attached." -Attachments "C:\Reports\monthly.xlsx" `
-SmtpServer "smtp.office365.com" -Port 587 -UseSsl -Credential $cred
# After
nylas email send --to "finance@company.com" `
--subject "Monthly Report" `
--body "Report attached." `
--attach "C:\Reports\monthly.xlsx" --yes
Multiple recipients with CC/BCC
# Before
Send-MailMessage -To "alice@team.com" -Cc "bob@team.com" `
-Bcc "manager@team.com" -Subject "Sprint update" `
-Body "All tasks on track." -SmtpServer "smtp.gmail.com"
# After
nylas email send --to "alice@team.com" `
--cc "bob@team.com" --bcc "manager@team.com" `
--subject "Sprint update" --body "All tasks on track." --yes
HTML email body
# Before
Send-MailMessage -To "team@company.com" -Subject "Status" `
-Body "<h1>All Green</h1><p>No incidents today.</p>" `
-BodyAsHtml -SmtpServer "smtp.office365.com"
# After
nylas email send --to "team@company.com" `
--subject "Status" `
--body "<h1>All Green</h1><p>No incidents today.</p>" --yes
Read and search email too
Unlike Send-MailMessage, which is send-only, Nylas CLI also reads your inbox:
# List recent emails
nylas email list --limit 10
# Search
nylas email search "invoice" --json | ConvertFrom-Json
# Unread count
(nylas email list --unread --json | ConvertFrom-Json).Count
Full guide: Read and Search Email in PowerShell
Scheduled sends
# Send tomorrow morning
nylas email send --to "team@company.com" `
--subject "Monday standup" --body "Agenda attached." `
--schedule "tomorrow 9am" --yes
Bulk send from CSV
Import-Csv contacts.csv | ForEach-Object {
nylas email send `
--to $_.Email `
--subject "Hello $($_.Name)" `
--body "Your account is ready." --yes
Start-Sleep -Seconds 2
}
For advanced mail merge with variable substitution, see CLI Mail Merge.
Task Scheduler automation
Replace your scheduled Send-MailMessage scripts by swapping the command:
# Create a scheduled task that sends a daily report
$Action = New-ScheduledTaskAction -Execute "nylas" `
-Argument 'email send --to "team@company.com" --subject "Daily Report" --body "Automated report" --yes'
$Trigger = New-ScheduledTaskTrigger -Daily -At "8:00AM"
Register-ScheduledTask -TaskName "DailyEmailReport" -Action $Action -Trigger $Trigger
Full automation guide: Automated Email Reports with PowerShell
Works with Office 365, Gmail, and more
The same commands work regardless of your email provider. No SMTP server changes when you switch providers:
Monitor your inbox
Build alerting scripts that watch for specific emails:
# Poll for emails from a specific sender
nylas email list --from "alerts@monitoring.com" --unread --json
Full guide: Monitor Your Inbox with PowerShell
CI/CD integration
Works in GitHub Actions and Azure DevOps pipelines:
# GitHub Actions
- name: Send deployment notification
run: |
nylas email send --to "team@company.com" \
--subject "Deployed v${{ github.ref_name }}" \
--body "Deployment complete." --yes
Full guide: Test Email in CI/CD with PowerShell
Step-by-step migration with every Send-MailMessage pattern: Replace Send-MailMessage with Nylas CLI
Related guides:
- Send Email from PowerShell
- Send Email from the Command Line
- Automate Email and Calendar in PowerShell
- Best CLI Email Tools Compared
- Extract OTP Codes from Email
- E2E Email Testing with Playwright
- SPF, DKIM, DMARC Debugging
All guides: cli.nylas.com/guides
Top comments (0)