Created
August 26, 2020 00:25
-
-
Save brettmillerb/3b3dd150959e09418841615901e86952 to your computer and use it in GitHub Desktop.
Send Grid Bounces
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
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 | |
} | |
} | |
} |
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
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