Tools: Latest: Replace Send-MailMessage in PowerShell — It's Deprecated

Tools: Latest: Replace Send-MailMessage in PowerShell — It's Deprecated

Before and after

Send-MailMessage (deprecated)

Nylas CLI (replacement)

Install on Windows

Authenticate once

Migration examples

Simple notification email

Email with attachment

Multiple recipients with CC/BCC

HTML email body

Read and search email too

Scheduled sends

Bulk send from CSV

Task Scheduler automation

Works with Office 365, Gmail, and more

Monitor your inbox

CI/CD integration 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. No SMTP server. No port. No credentials stored in your script. OAuth2 tokens are managed by the CLI and refreshed automatically. For macOS/Linux, use brew install nylas/nylas-cli/nylas. Full install options in the getting started guide. The CLI opens a browser for OAuth consent. After that, your scripts run unattended — no Get-Credential prompts, no stored passwords. Unlike Send-MailMessage, which is send-only, Nylas CLI also reads your inbox: Full guide: Read and Search Email in PowerShell For advanced mail merge with variable substitution, see CLI Mail Merge. Replace your scheduled Send-MailMessage scripts by swapping the command: Full automation guide: Automated Email Reports with PowerShell The same commands work regardless of your email provider. No SMTP server changes when you switch providers: Build alerting scripts that watch for specific emails: Full guide: Monitor Your Inbox with PowerShell Works in GitHub Actions and Azure DevOps pipelines: Full guide: Test Email in CI/CD with PowerShell Step-by-step migration with every Send-MailMessage pattern: Replace Send-MailMessage with Nylas CLI All guides: cli.nylas.com/guides Templates let you quickly answer FAQs or store snippets for re-use. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse

Command

Copy

# Old way — deprecated, insecure, requires SMTP config Send-MailMessage ` -From "[email protected]" ` -To "[email protected]" ` -Subject "Daily Report" ` -Body "See attached." ` -Attachments "report.csv" ` -SmtpServer "smtp.office365.com" ` -Port 587 ` -UseSsl ` -Credential (Get-Credential) # Old way — deprecated, insecure, requires SMTP config Send-MailMessage ` -From "[email protected]" ` -To "[email protected]" ` -Subject "Daily Report" ` -Body "See attached." ` -Attachments "report.csv" ` -SmtpServer "smtp.office365.com" ` -Port 587 ` -UseSsl ` -Credential (Get-Credential) # Old way — deprecated, insecure, requires SMTP config Send-MailMessage ` -From "[email protected]" ` -To "[email protected]" ` -Subject "Daily Report" ` -Body "See attached." ` -Attachments "report.csv" ` -SmtpServer "smtp.office365.com" ` -Port 587 ` -UseSsl ` -Credential (Get-Credential) # New way — OAuth, no SMTP, no credentials in scripts nylas email send ` --to "[email protected]" ` --subject "Daily Report" ` --body "See attached." ` --attach "report.csv" ` --yes # New way — OAuth, no SMTP, no credentials in scripts nylas email send ` --to "[email protected]" ` --subject "Daily Report" ` --body "See attached." ` --attach "report.csv" ` --yes # New way — OAuth, no SMTP, no credentials in scripts nylas email send ` --to "[email protected]" ` --subject "Daily Report" ` --body "See attached." ` --attach "report.csv" ` --yes # One-line -weight: 500;">install via PowerShell irm https://cli.nylas.com/-weight: 500;">install.ps1 | iex # Verify nylas --version # One-line -weight: 500;">install via PowerShell irm https://cli.nylas.com/-weight: 500;">install.ps1 | iex # Verify nylas --version # One-line -weight: 500;">install via PowerShell irm https://cli.nylas.com/-weight: 500;">install.ps1 | iex # Verify nylas --version nylas auth login nylas auth whoami # => Authenticated as [email protected] (Microsoft 365) nylas auth login nylas auth whoami # => Authenticated as [email protected] (Microsoft 365) nylas auth login nylas auth whoami # => Authenticated as [email protected] (Microsoft 365) # Before (Send-MailMessage) Send-MailMessage -To "[email protected]" -Subject "Build failed" ` -Body "CI pipeline failed at $(Get-Date)" -SmtpServer "smtp.gmail.com" # After (Nylas CLI) nylas email send --to "[email protected]" ` --subject "Build failed" ` --body "CI pipeline failed at $(Get-Date)" --yes # Before (Send-MailMessage) Send-MailMessage -To "[email protected]" -Subject "Build failed" ` -Body "CI pipeline failed at $(Get-Date)" -SmtpServer "smtp.gmail.com" # After (Nylas CLI) nylas email send --to "[email protected]" ` --subject "Build failed" ` --body "CI pipeline failed at $(Get-Date)" --yes # Before (Send-MailMessage) Send-MailMessage -To "[email protected]" -Subject "Build failed" ` -Body "CI pipeline failed at $(Get-Date)" -SmtpServer "smtp.gmail.com" # After (Nylas CLI) nylas email send --to "[email protected]" ` --subject "Build failed" ` --body "CI pipeline failed at $(Get-Date)" --yes # Before Send-MailMessage -To "[email protected]" -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 "[email protected]" ` --subject "Monthly Report" ` --body "Report attached." ` --attach "C:\Reports\monthly.xlsx" --yes # Before Send-MailMessage -To "[email protected]" -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 "[email protected]" ` --subject "Monthly Report" ` --body "Report attached." ` --attach "C:\Reports\monthly.xlsx" --yes # Before Send-MailMessage -To "[email protected]" -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 "[email protected]" ` --subject "Monthly Report" ` --body "Report attached." ` --attach "C:\Reports\monthly.xlsx" --yes # Before Send-MailMessage -To "[email protected]" -Cc "[email protected]" ` -Bcc "[email protected]" -Subject "Sprint -weight: 500;">update" ` -Body "All tasks on track." -SmtpServer "smtp.gmail.com" # After nylas email send --to "[email protected]" ` --cc "[email protected]" --bcc "[email protected]" ` --subject "Sprint -weight: 500;">update" --body "All tasks on track." --yes # Before Send-MailMessage -To "[email protected]" -Cc "[email protected]" ` -Bcc "[email protected]" -Subject "Sprint -weight: 500;">update" ` -Body "All tasks on track." -SmtpServer "smtp.gmail.com" # After nylas email send --to "[email protected]" ` --cc "[email protected]" --bcc "[email protected]" ` --subject "Sprint -weight: 500;">update" --body "All tasks on track." --yes # Before Send-MailMessage -To "[email protected]" -Cc "[email protected]" ` -Bcc "[email protected]" -Subject "Sprint -weight: 500;">update" ` -Body "All tasks on track." -SmtpServer "smtp.gmail.com" # After nylas email send --to "[email protected]" ` --cc "[email protected]" --bcc "[email protected]" ` --subject "Sprint -weight: 500;">update" --body "All tasks on track." --yes # Before Send-MailMessage -To "[email protected]" -Subject "Status" ` -Body "<h1>All Green</h1><p>No incidents today.</p>" ` -BodyAsHtml -SmtpServer "smtp.office365.com" # After nylas email send --to "[email protected]" ` --subject "Status" ` --body "<h1>All Green</h1><p>No incidents today.</p>" --yes # Before Send-MailMessage -To "[email protected]" -Subject "Status" ` -Body "<h1>All Green</h1><p>No incidents today.</p>" ` -BodyAsHtml -SmtpServer "smtp.office365.com" # After nylas email send --to "[email protected]" ` --subject "Status" ` --body "<h1>All Green</h1><p>No incidents today.</p>" --yes # Before Send-MailMessage -To "[email protected]" -Subject "Status" ` -Body "<h1>All Green</h1><p>No incidents today.</p>" ` -BodyAsHtml -SmtpServer "smtp.office365.com" # After nylas email send --to "[email protected]" ` --subject "Status" ` --body "<h1>All Green</h1><p>No incidents today.</p>" --yes # 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 # 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 # 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 # Send tomorrow morning nylas email send --to "[email protected]" ` --subject "Monday standup" --body "Agenda attached." ` --schedule "tomorrow 9am" --yes # Send tomorrow morning nylas email send --to "[email protected]" ` --subject "Monday standup" --body "Agenda attached." ` --schedule "tomorrow 9am" --yes # Send tomorrow morning nylas email send --to "[email protected]" ` --subject "Monday standup" --body "Agenda attached." ` --schedule "tomorrow 9am" --yes Import-Csv contacts.csv | ForEach-Object { nylas email send ` --to $_.Email ` --subject "Hello $($_.Name)" ` --body "Your account is ready." --yes Start-Sleep -Seconds 2 } Import-Csv contacts.csv | ForEach-Object { nylas email send ` --to $_.Email ` --subject "Hello $($_.Name)" ` --body "Your account is ready." --yes Start-Sleep -Seconds 2 } Import-Csv contacts.csv | ForEach-Object { nylas email send ` --to $_.Email ` --subject "Hello $($_.Name)" ` --body "Your account is ready." --yes Start-Sleep -Seconds 2 } # Create a scheduled task that sends a daily report $Action = New-ScheduledTaskAction -Execute "nylas" ` -Argument 'email send --to "[email protected]" --subject "Daily Report" --body "Automated report" --yes' $Trigger = New-ScheduledTaskTrigger -Daily -At "8:00AM" Register-ScheduledTask -TaskName "DailyEmailReport" -Action $Action -Trigger $Trigger # Create a scheduled task that sends a daily report $Action = New-ScheduledTaskAction -Execute "nylas" ` -Argument 'email send --to "[email protected]" --subject "Daily Report" --body "Automated report" --yes' $Trigger = New-ScheduledTaskTrigger -Daily -At "8:00AM" Register-ScheduledTask -TaskName "DailyEmailReport" -Action $Action -Trigger $Trigger # Create a scheduled task that sends a daily report $Action = New-ScheduledTaskAction -Execute "nylas" ` -Argument 'email send --to "[email protected]" --subject "Daily Report" --body "Automated report" --yes' $Trigger = New-ScheduledTaskTrigger -Daily -At "8:00AM" Register-ScheduledTask -TaskName "DailyEmailReport" -Action $Action -Trigger $Trigger # Poll for emails from a specific sender nylas email list --from "[email protected]" --unread --json # Poll for emails from a specific sender nylas email list --from "[email protected]" --unread --json # Poll for emails from a specific sender nylas email list --from "[email protected]" --unread --json # GitHub Actions - name: Send deployment notification run: | nylas email send --to "[email protected]" \ --subject "Deployed v${{ github.ref_name }}" \ --body "Deployment complete." --yes # GitHub Actions - name: Send deployment notification run: | nylas email send --to "[email protected]" \ --subject "Deployed v${{ github.ref_name }}" \ --body "Deployment complete." --yes # GitHub Actions - name: Send deployment notification run: | nylas email send --to "[email protected]" \ --subject "Deployed v${{ github.ref_name }}" \ --body "Deployment complete." --yes - Office 365 Email from PowerShell - Gmail OAuth in PowerShell - Download Email Attachments in PowerShell - 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