Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Last active October 17, 2020 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrenjrobinson/885c243dd74c6b3089a834e8ab3d5809 to your computer and use it in GitHub Desktop.
Save darrenjrobinson/885c243dd74c6b3089a834e8ab3d5809 to your computer and use it in GitHub Desktop.
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