Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson

darrenjrobinson/run.ps1

Last active Oct 17, 2020
Embed
What would you like to do?
PowerShell Azure Function SendGrid Output Binding example. Associated Blogpost https://blog.darrenjrobinson.com/using-the-azure-functions-sendgrid-output-binding-with-powershell/
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."
$inputData = $Request.Body | convertfrom-json
$emailSubject = $inputData.subject
$emailBody = $inputData.messageContent
$mail = @{
"personalizations" = @(
@{
"to" = @(
@{
"email" = "$($env:sendGridToAddress)"
}
)
}
)
"from" = @{
"email" = "$($env:sendGridFromAddress)"
}
"subject" = "$($emailSubject)"
"content" = @(
@{
"type" = "text/plain"
"value" = "$($emailBody)"
}
)
}
Push-OutputBinding -Name message -Value (ConvertTo-Json -InputObject $mail -Depth 4)
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $mail
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.