Last active
October 17, 2020 05:12
-
-
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/
This file contains 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 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