PowerShell NavigationCmdletProvider for IMAP / POP3 / SMTP.
Navigate your mailbox like a filesystem using cd, dir, cat, mv, del and other familiar commands.
- IMAP / POP3 / SMTP via MailKit
- Folder operations — create, rename, delete, subscribe/unsubscribe
- Message operations — read, move, copy, delete (Trash), flag, search
- Send / Reply / Forward with attachments
- Gmail native search —
X-GM-RAWpowered server-side search (has:attachment,from:, etc.) - OAuth2 — Device Code Flow for Microsoft 365 / Azure AD
- Bulk export —
.emlbackup with incremental skip, attachment extraction from local.emlfiles - Unified view — folders (blue) and messages in the same table
- Auto-reconnect — transparent retry on connection drop
- PowerShell 7.4+
- .NET 9.0
Import-Module MailDrive
Open-MailConfig# Opens config in notepad — add your mail accountImport-MailConfig# Mount drives from config
cd Gmail:\INBOX
dir # List messages
dir -Search "from:boss"# Gmail native search
cat .\1_sender_subject.eml # Read message bodyConfig file location: Get-MailConfigPath
{
"PSDrives": [
{
"Name": "Gmail",
"Protocol": "IMAP",
"Host": "imap.gmail.com",
"Port": 993,
"Ssl": "SslOnConnect",
"Username": "you@gmail.com",
"Password": "xxxx xxxx xxxx xxxx",
"SmtpHost": "smtp.gmail.com",
"SmtpPort": 465,
"SmtpSsl": "SslOnConnect"
}
]
}For Gmail, generate an App Password (requires 2-Step Verification).
cd Gmail:\INBOX # Enter INBOX
dir # List folders and messages
dir -First 50# Show latest 50 messages
dir -Force # Refresh cache
cd ..# Go upcat .\1_sender_subject.eml # Read message body
dir -Search "has:attachment"# Gmail: server-side search
dir -Search "from:alice subject:meeting"# Multiple conditionsSend-Mail-To user@example.com-Subject "Hello"-Body "Hi there"Send-Mail-To user@example.com-Subject "Report"-Body "See attached"-Attachments .\report.pdfGet-Item .\1_sender_subject.eml |Submit-MailReply"Thanks!"Get-Item .\1_sender_subject.eml |Submit-MailForward-To colleague@example.commkdir Gmail:\Archive # Create folder
mv .\1_sender_subject.eml Gmail:\Archive # Move message
del .\2_sender_subject.eml # Move to Trash
del .\2_sender_subject.eml -Force # Permanent deleteRename-Item Gmail:\OldName Gmail:\NewName# Bulk backup (skips existing files by default)
dir Gmail:\INBOX |Export-MailMessage C:\backup\Gmail
# With folder structure preserved
dir Gmail:\ -Recurse |Export-MailMessage C:\backup\Gmail
# Extract attachments from serverGet-Item .\1_sender_subject.eml |Export-MailAttachment C:\temp\
# Extract attachments from local .eml (including embedded images)Get-Item C:\backup\message.eml |Export-MailAttachment C:\temp\ -IncludeEmbeddedSet-ItemProperty .\1_sender_subject.eml -Name IsFlagged -Value $trueClear-ItemProperty .\1_sender_subject.eml -Name IsFlagged| Cmdlet | Description |
|---|---|
New-MailDrive | Create an IMAP drive |
New-PopDrive | Create a POP3 drive |
Import-MailConfig | Mount drives from config file |
Open-MailConfig | Open config in editor |
Get-MailConfigPath | Show config file path |
Send-Mail | Send a message via SMTP |
Submit-MailReply | Reply to a message |
Submit-MailForward | Forward a message |
Export-MailMessage | Export messages as .eml files |
Export-MailAttachment | Extract attachments |
New-MailDraft | Save a draft (IMAP) |
Get-MailQuota | Query IMAP quota |
MailDrive works as an email MCP server when combined with PowerShell.MCP.
{
"mcpServers": {
"pwsh": {
"command": "pwsh",
"args": ["-NoProfile", "-Command", "Import-Module PowerShell.MCP; Start-MCPServer"]
}
}
}Once connected, AI agents can read, search, send, and manage email through standard PowerShell commands:
# Agent reads inbox
invoke_expression: "dir Gmail:\\INBOX"
# Agent reads a specific message
invoke_expression: "cat 'Gmail:\\INBOX\\28_Google_Security.eml'"
# Agent searches for invoices
invoke_expression: "dir Gmail:\\INBOX -Search 'has:attachment from:Microsoft'"
# Agent sends email
invoke_expression: "Send-Mail -To user@example.com -Subject 'Report' -Body 'Done'"
# Agent exports attachments
invoke_expression: "Get-Item 'Gmail:\\INBOX\\23_Microsoft_Invoice.eml' | Export-MailAttachment C:\\temp"
No dedicated mail MCP server needed — the PowerShell provider acts as the interface.
See GREENMAIL.md for local testing with GreenMail.
.\build.ps1
Import-Module MailDrive -ForcePer-cmdlet documentation lives under docs/help/<locale>/. English (en-US/)
is the only locale shipped today; the layout supports additional locales.
| Action | Command |
|---|---|
| View help offline | Get-Help <cmdlet> -Full |
| Open online version | Get-Help <cmdlet> -Online |
| Regenerate from cmdlet metadata | .\docs\build-help.ps1 |
The build script uses PlatyPS: it
refreshes the markdown skeletons (preserving any prose you've written),
patches per-cmdlet online URLs, and compiles MAML into
<module>/<locale>/MailDrive.dll-Help.xml so Get-Help works without a
network round trip. To bootstrap a new locale, run with
-Locales en-US, ja-JP etc. — each new locale starts from scratch and is
yours to translate.
MIT