Skip to content

Instantly share code, notes, and snippets.

View gscales's full-sized avatar

Glen Scales gscales

View GitHub Profile
$mailbox = "[email protected]"
# PSETID_Note GUID
$noteGuid = "0006200E-0000-0000-C000-000000000046"
# Build sticky note payload
$body = @{
subject = "" # Sticky notes typically have no subject
body = @{
contentType = "Text"
content = "This is a sticky note created via Microsoft Graph"
private static readonly Guid PSETID_Note = new Guid("{0006200E-0000-0000-C000-000000000046}");
Item note = new Item(service);
note.ItemClass = "IPM.StickyNote";
// 3. Set basic content
note.Subject = "My EWS Sticky Note";
note.Body = "This is the content of the sticky note.\nCreated via EWS Managed API.";
// 4. Define Extended Properties (based on MS-OXONOTE spec)
We couldn’t find that file to show.
@gscales
gscales / gist:899093311585eab39edca2c37da72ef7
Last active November 27, 2025 02:56
Authentication in Exchange Admin API using Graph MSAL
Import-Module Microsoft.Graph.Authentication -ErrorAction Stop
$graphModule = Get-Module Microsoft.Graph.Authentication
$msalDll = Get-ChildItem -Path $graphModule.ModuleBase -Filter "Microsoft.Identity.Client.dll" -Recurse | Select-Object -First 1
if ($msalDll) {
Add-Type -Path $msalDll.FullName
Write-Host "Microsoft.Identity.Client loaded successfully from: $($msalDll.FullName)"
}
else {
Write-Error "Microsoft.Identity.Client.dll not found"
}
@gscales
gscales / gist:0a1a9964af33132fbc2de1c1055b9a56
Created April 1, 2022 04:55
Example for using OAuth against Office365 in Open Pop using fork https://github.com/gscales/hpop , MSAL and ROPC
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);
@gscales
gscales / gist:8a8eafc85029ce31f01f0a289469d46d
Created January 14, 2022 00:32
CustomTokenCredentials implmenation
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;
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"
},
@gscales
gscales / gist:02b32a66dfb0b11792b8a2d852188086
Last active August 22, 2021 23:53
Send Mail via Microsoft Graph using MIMEKit, Graph SDK and MSAL
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;
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]
<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">