This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NetworkCredential networkCredential = new NetworkCredential("[email protected]", "blah"); | |
| PublicClientApplicationBuilder pcaConfig = PublicClientApplicationBuilder.Create("d64799fe-dfb2-480b-a3be-a7a5a0bdaf32").WithTenantId("eb8db77e-65e0-4fc3-b967-b14d5057375b"); | |
| var app = pcaConfig.Build(); | |
| var tokenResult = app.AcquireTokenByUsernamePassword(new string[] { "https://outlook.office.com/POP.AccessAsUser.All" }, networkCredential.UserName, networkCredential.SecurePassword).ExecuteAsync().GetAwaiter().GetResult(); | |
| var saslformatedToken = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes("user=" + networkCredential.UserName + (char)1 + "auth=Bearer " + tokenResult.AccessToken + (char)1 + (char)1)); | |
| var client = new Pop3Client(); | |
| client.Connect("outlook.office365.com", 995, true); | |
| client.Authenticate(networkCredential.UserName, saslformatedToken, AuthenticationMethod.XOAUTH2); | |
| int messageCount = client.GetMessageCount(); | |
| var lastMessage = client.GetMessage(messageCount); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using Microsoft.Exchange.WebServices.Data; | |
| using System.Threading.Tasks; | |
| using System.Net; | |
| using System.Security; | |
| using Microsoft.Identity.Client; | |
| using System.Net.Http; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Create a Draft message | |
| POST https://graph.microsoft.com/v1.0/users('[email protected]')/mailfolders/drafts/messages HTTP/1.1 | |
| { | |
| "Subject": "Test Message 1234", | |
| "Body": { | |
| "ContentType": "HTML", | |
| "Content": "Rgds Glen" | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using System.Net.Http; | |
| using System.Net.Http.Headers; | |
| using Microsoft.Identity.Client; | |
| using Newtonsoft.Json; | |
| using Microsoft.Graph; | |
| using System.IO; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Get-AccessTokenForGraphFromCertificate{ | |
| param( | |
| [Parameter(Position = 1, Mandatory = $true)] | |
| [String] | |
| $TenantDomain, | |
| [Parameter(Position = 2, Mandatory = $true)] | |
| [String] | |
| $ClientId, | |
| [Parameter(Position = 3, Mandatory = $false)] | |
| [System.Security.Cryptography.X509Certificates.X509Certificate2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <soap:Envelope | |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" | |
| xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" | |
| xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> | |
| <soap:Header> | |
| <t:RequestServerVersion Version="Exchange2016" /> | |
| </soap:Header> | |
| <soap:Body> | |
| <m:FindItem Traversal="Shallow"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Extended property Definition for isExternalSender | |
| $isExternalSender = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Guid]::Parse("41F28F13-83F4-4114-A584-EEDB5A6B0BFF"),"IsExternalSender", [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Boolean) | |
| Using it in FindItems | |
| $ItemPropset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties) | |
| $ItemPropset.Add($isExternalSender) | |
| $ivItemView = New-Object Microsoft.Exchange.WebServices.Data.ItemView(1000) | |
| $ivItemView.PropertySet = $ItemPropset |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Include the IsExternalSender property in Results | |
| https://graph.microsoft.com/v1.0/users('[email protected]')/MailFolders('Inbox')/messages/? | |
| $Top=10&$expand=SingleValueExtendedProperties($filter=(Id eq 'Boolean {41F28F13-83F4-4114-A584-EEDB5A6B0BFF} Name IsExternalSender')) | |
| Filter for only External Senders | |
| https://graph.microsoft.com/v1.0/users('[email protected]')/MailFolders('Inbox')/messages/? | |
| $Top=10&$filter=singleValueExtendedProperties/Any(ep:+ep/id+eq+'Boolean+{41F28F13-83F4-4114-A584-EEDB5A6B0BFF}+Name+IsExternalSender'+and+cast(ep/value,+Edm.Boolean)+eq+true)&$expand=SingleValueExtendedProperties($filter=(Id eq 'Boolean {41F28F13-83F4-4114-A584-EEDB5A6B0BFF} Name IsExternalSender')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function FindFolderRequest(){ | |
| var RequestString = | |
| '<?xml version="1.0" encoding="utf-8"?>' + | |
| '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' + | |
| ' <soap:Header>' + | |
| ' <t:RequestServerVersion Version="Exchange2016" />' + | |
| ' </soap:Header>' + | |
| ' <soap:Body>' + | |
| '<m:FindFolder Traversal="Shallow">' + | |
| '<m:FolderShape>' + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName) | |
| $TeamsMessagesDataFolderEntryId = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([System.Guid]::Parse("{E49D64DA-9F3B-41AC-9684-C6E01F30CDFA}"), "TeamsMessagesDataFolderEntryId", [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary); | |
| $psPropset= new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties) | |
| $psPropset.Add($TeamsMessagesDataFolderEntryId) | |
| $RootFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid,$psPropset) | |
| if ($RootFolder.TryGetProperty($TeamsMessagesDataFolderEntryId,[ref]$FolderIdVal)) | |
| { | |
| $TeamsMessagesFolderId= new-object Microsoft.Exchange.WebServices.Data.FolderId((ConvertId -HexId ([System.BitConverter]::ToString($FolderIdVal).Replace("-","")) -service $service)) | |
| $TeamsMessagesDataFolder = |
NewerOlder