Skip to content

Instantly share code, notes, and snippets.

@brettmillerb
Created August 26, 2020 00:25
Show Gist options
  • Save brettmillerb/3b3dd150959e09418841615901e86952 to your computer and use it in GitHub Desktop.
Save brettmillerb/3b3dd150959e09418841615901e86952 to your computer and use it in GitHub Desktop.
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