Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Send Grid Bounces
function Get-SendGridBouncedAddress {
[CmdletBinding()]
param (
[string[]]
$EmailAddress,
[string]
$Token
)
begin {
$headers = @{
accept = 'application/json'
authorization = 'bearer {0}' -f $token
}
}
process {
foreach ($email in $EmailAddress) {
$invokeRestMethodSplat = @{
Uri = 'https://api.sendgrid.com/v3/suppression/bounces/{0}' -f $EmailAddress
Headers = $headers
Method = 'Get'
}
$result = Invoke-RestMethod @invokeRestMethodSplat
$result | Select-Object @{name='EmailAddress';expression={$result.email}}, reason, status
}
}
}
function Remove-SendGridBouncedAddress {
[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
param (
[Parameter(Mandatory,
ValueFromPipelineByPropertyName)]
[string[]]
$EmailAddress,
[string]
$Token
)
begin {
$headers = @{
accept = 'application/json'
authorization = 'bearer {0}' -f $token
}
}
process {
foreach ($email in $EmailAddress) {
if ($PSCmdlet.ShouldProcess("$email", "Removing Bounced Email Address:")) {
$invokeRestMethodSplat = @{
Uri = 'https://api.sendgrid.com/v3/suppression/bounces/{0}' -f $EmailAddress
Headers = $headers
Method = 'Delete'
}
$result = Invoke-RestMethod @invokeRestMethodSplat
$result
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment