Skip to content

Instantly share code, notes, and snippets.

@cdhunt
Last active May 22, 2020 23:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdhunt/f03c6f33ed50323ab6ac to your computer and use it in GitHub Desktop.
Save cdhunt/f03c6f33ed50323ab6ac to your computer and use it in GitHub Desktop.
Browse your email from PowerShell like a folder
Import-Module Simplex
New-PSDrive mail -psprovider simplex -root "C:\Temp\outlookprov.ps1"
cd mail:\Inbox
Add-type -assembly "Microsoft.Office.Interop.Outlook" | Out-Null
$olFolders = "Microsoft.Office.Interop.Outlook.olDefaultFolders" -as [type]
$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace("MAPI")
$inbox = $namespace.getDefaultFolder($olFolders::olFolderInBox)
root {
script Inbox {
$inbox.Items
}
$inbox.Folders | foreach-object {
$subFolder = $_
$content = Split-Path $subFolder.folderpath -Leaf
script "$content" {
$subFolder.Items
}.GetNewClosure();
}
}
function Send-MailReply
{
[CmdletBinding()]
Param
(
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
Position=1)]
$InputObject,
# Param2 help description
[Parameter(Mandatory=$true,
Position=0)]
[string]
$To
)
Process
{
$newMessage = $InputObject.Reply()
$newMessage.To = $To
$newMessage.Send()
}
}
function Send-MailForward
{
[CmdletBinding()]
Param
(
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
Position=1)]
$InputObject,
# Param2 help description
[Parameter(Mandatory=$true,
Position=0)]
[string]
$To
)
Process
{
$newMessage = $InputObject.Forward()
$newMessage.To = $To
$newMessage.Send()
}
}
# Example
PS mail:\Inbox> ls | select -first 1 | Send-MailForward someemail@mydomain.me
@cdhunt
Copy link
Author

cdhunt commented Oct 30, 2015

The child of Get Outlook Inbox and Simplex.

@cdhunt
Copy link
Author

cdhunt commented Nov 1, 2015

Added example Reply and Forward functions.

@cdhunt
Copy link
Author

cdhunt commented Nov 1, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment