Skip to content

Instantly share code, notes, and snippets.

@baywet
Created September 8, 2021 13:36
Embed
What would you like to do?
AGS request payload compression test
$accessToken = "<AccessTokenWithMailSendPermission>"
$srcFileName = "PathToRequestPayloadUncompress-SeeOtherFile"
$destFileName = "APath"
$srcFileStream = New-Object System.IO.FileStream($srcFileName,([IO.FileMode]::Open),([IO.FileAccess]::Read),([IO.FileShare]::Read))
$destFileStream = New-Object System.IO.FileStream($destFileName,([IO.FileMode]::Create),([IO.FileAccess]::Write),([IO.FileShare]::None))
$gzip = New-Object System.IO.Compression.GZipStream($destFileStream,[System.IO.Compression.CompressionMode]::Compress)
$gzip.CopyTo($srcFileStream)
$gzip.Flush()
$destFileStream.Dispose()
Invoke-WebRequest -UseBasicParsing -Uri "https://graph.microsoft.com/v1.0/me/sendMail" `
-Method "POST" `
-Headers @{
"Authorization"="Bearer $accessToken"
"Accept"="*/*"
"Accept-Encoding"="gzip, deflate, br"
"Content-Encoding"="gzip"
} `
-ContentType "application/json" `
-InFile $destFileName
{"message":{"subject":"Meet for lunch?","body":{"contentType":"Text","content":"The new cafeteria is open."},"toRecipients":[{"emailAddress":{"address":"jane@contoso.onmicrosoft.com"}}]}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment