Skip to content

Managing Suppressions

Vlad-Cosmin Sandu edited this page Apr 6, 2020 · 1 revision

The PostmarkClient allows you to create, delete (reactivate) or search for Suppressed recipients.

Get Suppressed Recipients:

var query = new PostmarkSuppressionQuery
{
    SuppressionReason = "ManualSuppression", // filter by Suppression reason [optional]
    Origin = "Customer", // filter by Suppression Origin [optional]
    EmailAddress = "[email protected]", // filter by email address [optional]
    FromDate = DateTime.UtcNow.AddDays(-2), // filter from the specified date [optional]
    ToDate = DateTime.UtcNow.AddDays(-1) // filter up to the specified date [optional]
};

var suppressionListing = await _client.ListSuppressions(query);

foreach (var suppression in suppressionListing.Suppressions)
{
    Console.WriteLine($"EmailAddress: {suppression.EmailAddress}");
    Console.WriteLine($"SuppressionReason: {suppression.SuppressionReason}");
    Console.WriteLine($"Origin: {suppression.Origin}");
    Console.WriteLine($"CreatedAt: {suppression.CreatedAt.ToString("O")}");
}

Create Suppressions:

var request = new PostmarkSuppressionChangeRequest { EmailAddress = "[email protected]" };
var result = await _client.CreateSuppressions(new List<PostmarkSuppressionChangeRequest> { request });

foreach (var suppressionRequest in result.Suppressions)
{
    Console.WriteLine($"EmailAddress: {suppressionRequest.EmailAddress}"); // EmailAddress to suppress
    Console.WriteLine($"Status: {suppressionRequest.Status.ToString()}"); // Status of the request
    Console.WriteLine($"Message: {suppressionRequest.Message}"); // Optional message about the request. E.g.: Reason for failure
}

Suppressions will be generated with a Customer Origin and will have a ManualSuppression reason.

Note: Requests are processed asynchronously and can take a minute until they become active.

Delete Suppressions:

var request = new PostmarkSuppressionChangeRequest { EmailAddress = "[email protected]" };
var result = await _client.DeleteSuppressions(new List<PostmarkSuppressionChangeRequest> { request });

foreach (var reactivationRequest in result.Suppressions)
{
    Console.WriteLine($"EmailAddress: {reactivationRequest.EmailAddress}"); // EmailAddress to reactivate
    Console.WriteLine($"Status: {reactivationRequest.Status.ToString()}"); // Status of the request
    Console.WriteLine($"Message: {reactivationRequest.Message}"); // Optional message about the request. E.g.: Reason for failure
}

Suppressions will only be reactivated if you have the required authority.

Note: Requests are processed asynchronously and can take a minute until they become active.

For more information, please check our Suppressions API Documentation.

Clone this wiki locally