Simple Mail Gui for the Microsoft Graph PowerShell SDK
I wrote the original PowerShell Simple Mail Gui in EWS (Exchange Web Services) quite some time ago and while it did also have an integration in the Exch-Rest library it was time to rewrite this so it will work with the Graph SDK and PowerShell 7
What is it
It’s a simple Mail Gui done in PowerShell that lets you Read, Search, Examine and send email from an Exchange Online mailbox that uses the Microsoft Graph PowerShell SDK cmdlets to do the actual underlying .
Where is the code and how to start using it
The code is on GitHub here https://github.com/gscales/Powershell-Scripts/blob/master/Graph101/GraphSDK/SimpleMailClient.ps1 , its a script module so to start using it all you need is something like
Import-module .\SimpleMailClient.ps1
To start the Gui you first need to connect to the Microsoft Graph using the Graph SDK Connect-mggraph with the following scopes “Mail.Read,Mail.Read.Shared,Mail.Send” eg
Connect-MgGraph -Scopes "Mail.Read,Mail.Read.Shared,Mail.Send"
Connect-MgGraph has a number of different authentication options so if you want to use it with App permission you can do so eg using a clientsecret
# Convert the Client Secret to a Secure String
$SecureClientSecret = ConvertTo-SecureString -String $ApplicationClientSecret -AsPlainText -Force
# Create a PSCredential Object Using the Client ID and Secure Client Secret
$ClientSecretCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ApplicationClientId, $SecureClientSecret
# Connect to Microsoft Graph Using the Tenant ID and Client Secret Credential
Connect-MgGraph -TenantId $TenantId -ClientSecretCredential $ClientSecretCredential
or using a Certificate which is better idea then a secret see example in
The you can start the Simple Mail Client using
Start-SMCMailClient -MailboxName mailbox@domain.com
What this will do is then try to enumerate all the folders in a Mailbox a process I explained in https://github.com/gscales/Powershell-Scripts/blob/0dfba190e15c6c1df18c17d6bf101c3aac1e0588/Graph101/GraphSDK/GraphSDK-EWSFolderTips.md
This should then generate something like following
This shows the enumerated mailbox folders (eg those with a folderclass(or subclass) of IPF.Folder, and it also show the first 100 items from the Inbox which are retrieved using
Get-MgUserMailFolderMessage -UserId $emEmailAddressTextBox.Text -MailFolderId $folder.id -Top $neResultCheckNum.Value -Search $sfilter -ExpandProperty (Get-ExtendedPropList -PropertyList $props)
The extended property I’m using is PidTagMessageSize which allows you to see the size of a Message (why that isn’t a strongly typed property in the Graph is beyond me).
There are a few other buttons that first let you look at the Message and render the html body eg
You can also look at the full Transport Headers using the pidTagTransportMessageHeaders property (rather then the Graph Internet Headers collection that doesn’t show everything) eg
You can also send a New Message which uses the Send-MgUserMail cmdlet and Export a Message to Mime which makes use of the Get-MgUserMessageContent cmdlet.
It supports 3 basic search one on Subject, From and Body of the Message they can be used like
One other thing you can do with this is if you want to target the Non Ipm Subtree of the Mailbox you can use
Start-SMCMailClient -MailboxName mailbox@domain.onmicrosoft.com -FolderName root
You will get a root mailbox view like
Which will list all the mail folders that can be enumerated with the Microsoft Graph which doesn’t represent the entirety of the Mailbox (You should use MFCMapi or OutlookSpy for that). But this is useful for giving a view of what you can see in the Graph.
One thing to note is that it doesn’t support the Dumpster/Recoverable Items folder because some of the cmds use the AllItems folder scope. So if you did want to use if for this it would require some tweaking.
This script for the Gui is located here https://github.com/gscales/Powershell-Scripts/blob/master/Graph101/GraphSDK/SimpleMailClient.ps1