client.Subscriptions
Every method in this namespace: its signature, its parameters, what it returns and an example.
Methods
The newsletters and mailing lists the mailbox receives: list them by sender or by domain, unsubscribe, and move what they send.
Subscriptions.ListAsync
List subscriptions
Task<JsonObject> ListAsync( string? status = null, string? q = null, string? sort = null, bool? suggested = null, int? limit = null, int? offset = null, string? address = null, string? apiKey = null, CancellationToken cancellationToken = default)Returns the newsletters and mailing lists the mailbox receives, as the Subscriptions page of the app shows them: one row per sender and the address it writes to, found from the List-Unsubscribe header of the mail it sends. Each row says how much mail the sender sent, how much of it is unread, readPercent (the share of it you read, 0 to 100) and how much arrived in the last 30 days, how it lets you unsubscribe, and the rule that keeps moving its new mail when there is one.
suggested marks an active sender worth leaving: it can be unsubscribed, sent at least 5 emails, wrote in the last 30 days and has 10% or less of its mail read. suggested: true lists only those.
status: is active, the default, kept for the ones you chose to keep with Subscriptions.KeepAsync, or unsubscribed. q: searches the sender, and sort: is recent, most, emails (most mail overall), read (least read first), unread or name. Paging is by offset:: total counts every match and hasMore says whether another page follows.
A key limited to particular addresses lists only the subscriptions delivered to them, and address: narrows the list to one address.
Parameters
statusstring?active,keptorunsubscribed. Defaults toactive.qstring?Searches the sender name and address.
sortstring?recent,most,emails,read,unreadorname, also inNextmail\Constants\SubscriptionSorts. Defaults torecent.suggestedbool?Only the senders worth unsubscribing from, the rows whose
suggestedis true.limitint?Rows per page, 1 to 200, defaulting to 50.
offsetint?How many rows to skip.
addressstring?Only the subscriptions delivered to this address.
apiKeystring?Overrides the client's API key for this call only.
cancellationTokenCancellationTokenCancels the request.
Returns
A JsonObject, not a Page, with object set to list, data, total, counts and hasMore, where counts holds how many are active, kept and unsubscribed.
Example
using Nextmail.Constants; var subscriptions = await client.Subscriptions.ListAsync(sort: SubscriptionSorts.Emails, limit: 20); foreach (var row in subscriptions["data"]?.AsArray() ?? []){ Console.WriteLine($"{row?["senderEmail"]} {row?["total"]} messages, {row?["readPercent"]}% read, suggested: {row?["suggested"]}");} Console.WriteLine($"{subscriptions["counts"]?["kept"]} kept, {subscriptions["counts"]?["unsubscribed"]} already unsubscribed");Notes
Read only, so the SDK retries it after a network failure like any other read.
Also available in
Subscriptions.ListDomainsAsync
List subscriptions by domain
Task<JsonObject> ListDomainsAsync( string? status = null, string? q = null, string? sort = null, bool? suggested = null, int? limit = null, int? offset = null, string? address = null, string? apiKey = null, CancellationToken cancellationToken = default)Returns the same subscriptions as Subscriptions.ListAsync, one row per sender domain with the counts of its senders added up, so a company that writes from several addresses is one row. unsubscribable counts the senders on the domain that can be unsubscribed without a person opening a page, which is what Subscriptions.UnsubscribeDomainAsync acts on, and readPercent is the share of the domain's mail you read.
It takes the same filters as Subscriptions.ListAsync, and suggested: true lists the domains of the suggested senders.
Parameters
statusstring?active,keptorunsubscribed. Defaults toactive.qstring?Searches the sender name and address.
sortstring?recent,most,emails,read,unreadorname. Defaults torecent.suggestedbool?Only the senders worth unsubscribing from, the rows whose
suggestedis true.limitint?Rows per page, 1 to 200, defaulting to 50.
offsetint?How many rows to skip.
addressstring?Only the subscriptions delivered to this address.
apiKeystring?Overrides the client's API key for this call only.
cancellationTokenCancellationTokenCancels the request.
Returns
A JsonObject, not a Page, with object set to list, data, total, counts and hasMore.
Example
var domains = await client.Subscriptions.ListDomainsAsync(sort: "most"); foreach (var row in domains["data"]?.AsArray() ?? []){ Console.WriteLine($"{row?["domain"]}: {row?["senders"]} senders, {row?["unsubscribable"]} can be unsubscribed here");}Notes
Read only, so the SDK retries it after a network failure like any other read.
Also available in
Subscriptions.KeepAsync
Keep subscriptions you want
Task<JsonObject> KeepAsync( IEnumerable<string> ids, IReadOnlyDictionary<string, object?>? body = null, string? apiKey = null, CancellationToken cancellationToken = default)Marks active subscriptions as ones you want, as Keep on the Subscriptions page does: they move from active to kept, are never suggested again and are left alone by Subscriptions.UnsubscribeDomainAsync. ["kept"] = false puts kept subscriptions back to active.
updated holds the subscriptions that changed. A subscription already in that state, or one you unsubscribed from, comes back in skipped, and an id that is unknown or delivered to an address the key does not reach in missing.
Parameters
idsIEnumerable<string>Required1 to 100 subscription ids from
Subscriptions.ListAsync. A repeated id counts once.keptbooltruekeeps them,falseputs them back to active. Defaults to true.apiKeystring?Overrides the client's API key for this call only.
cancellationTokenCancellationTokenCancels the request.
Returns
A JsonObject with object set to subscription_batch_keep, kept, updated, skipped and missing, each list holding subscription ids.
Example
var result = await client.Subscriptions.KeepAsync(new[] { "sub_7d2c1f0a9b3e4c5d6e7f8a9b" }); Console.WriteLine($"{result["updated"]?.AsArray().Count} kept, {result["skipped"]?.AsArray().Count} already kept or unsubscribed");Notes
The SDK retries it after a network failure, which is safe because keeping a kept subscription changes nothing.
Also available in
Subscriptions.UnsubscribeAsync
Unsubscribe from a sender
Task<JsonObject> UnsubscribeAsync( string id, IReadOnlyDictionary<string, object?>? body = null, string? apiKey = null, CancellationToken cancellationToken = default)Unsubscribes the way the sender asks for it: a one-click request to its unsubscribe address when it offers one, otherwise an unsubscribe email sent from the address the mail arrived at. A sender that only offers a page cannot be unsubscribed by a program, so method is link and url is the page a person has to open. bin set to true also moves every conversation from the sender to the Bin, and archive set to true archives them instead. bin wins when both are true.
A sender that gives no way to unsubscribe is a 422 unsubscribe_unsupported, and one whose one-click request failed with no address to write to is a 502 unsubscribe_refused. A subscription delivered to an address the key does not reach is a 404.
Parameters
idstringRequiredThe subscription, from
Subscriptions.ListAsync.binboolAlso move every conversation from the sender to the Bin. Defaults to false.
archiveboolAlso archive every conversation from the sender. Defaults to false.
apiKeystring?Overrides the client's API key for this call only.
cancellationTokenCancellationTokenCancels the request.
Returns
A JsonObject with object set to unsubscribe, subscriptionId, method, url, binned and archived.
Example
var result = await client.Subscriptions.UnsubscribeAsync("sub_7d2c1f0a9b3e4c5d6e7f8a9b", body: new Body { ["bin"] = true }); if ((string?)result["method"] == "link"){ Console.WriteLine($"Open {result["url"]} to finish unsubscribing");}else{ Console.WriteLine($"Unsubscribed by {result["method"]}, {result["binned"]} conversations binned");}Notes
The SDK does not retry it, because a second call can send a second unsubscribe email.
Also available in
Subscriptions.UnsubscribeManyAsync
Unsubscribe from up to 100 senders in one call
Task<JsonObject> UnsubscribeManyAsync( IEnumerable<string> ids, IReadOnlyDictionary<string, object?>? body = null, string? apiKey = null, CancellationToken cancellationToken = default)Unsubscribes from each subscription in ids the way Subscriptions.UnsubscribeAsync does for one, as Unsubscribe on a selection of the Subscriptions page does, and reports the rest instead of failing. unsubscribed holds the ones done with a one-click request or an unsubscribe email.
A sender that only unsubscribes on its own page comes back in links with the url a person has to open, and stays active until somebody does. skipped holds the ones already unsubscribed (already_unsubscribed) or that give no way to unsubscribe (no_method), failed the ones whose sender did not accept it, and missing the ids that are unknown or delivered to an address the key does not reach.
archive set to true also archives every conversation from the senders that were unsubscribed, and bin set to true moves them to the Bin instead.
Parameters
idsIEnumerable<string>Required1 to 100 subscription ids from
Subscriptions.ListAsync, for example the rows whosesuggestedis true. A repeated id counts once.archiveboolAlso archive every conversation from the senders. Defaults to false.
binboolAlso move every conversation from the senders to the Bin. Defaults to false.
apiKeystring?Overrides the client's API key for this call only.
cancellationTokenCancellationTokenCancels the request.
Returns
A JsonObject with object set to subscription_batch_unsubscribe, unsubscribed, links, skipped, failed, missing, binned and archived. Each entry of links is an object with id and url, and each entry of skipped an object with id and reason.
Example
var suggested = await client.Subscriptions.ListAsync(suggested: true);var ids = (suggested["data"]?.AsArray() ?? []).Select(row => (string?)row?["id"]).OfType<string>().ToList();var result = await client.Subscriptions.UnsubscribeManyAsync(ids, body: new Body { ["archive"] = true }); Console.WriteLine($"{result["unsubscribed"]?.AsArray().Count} unsubscribed, {result["archived"]} archived"); foreach (var step in result["links"]?.AsArray() ?? []){ Console.WriteLine($"Open {step?["url"]} to finish unsubscribing");}Notes
A partial result returns rather than throws, so read
links,skipped,failedandmissingto see what stayed.The SDK does not retry it, because a second call can send unsubscribe emails again.
Also available in
- API
POST /subscriptions/batch-unsubscribe- TypeScript
nextmail.subscriptions.unsubscribeMany()- Python
subscriptions.unsubscribe_many()- Ruby
subscriptions.unsubscribe_many- PHP
subscriptions->unsubscribeMany- Go
Subscriptions.UnsubscribeMany- Java
subscriptions().unsubscribeMany- CLI
nextmail subscriptions unsubscribe-many
Subscriptions.UnsubscribeDomainAsync
Unsubscribe from a whole domain
Task<JsonObject> UnsubscribeDomainAsync( string domain, IReadOnlyDictionary<string, object?>? body = null, string? apiKey = null, CancellationToken cancellationToken = default)Unsubscribes from every sender on a domain that can be unsubscribed without a person opening a page, with a one-click request or an unsubscribe email, as the domain view of the Subscriptions page does. unsubscribed counts the senders it worked for, skipped the senders that only offer a page and failed the ones that did not accept it.
Senders you kept with Subscriptions.KeepAsync are left alone. bin set to true also moves their conversations to the Bin, archive set to true archives them instead, and address keeps it to the subscriptions delivered to one address. A key limited to particular addresses acts only on the subscriptions delivered to them.
Parameters
domainstringRequiredThe sender domain, from
Subscriptions.ListDomainsAsync.binboolAlso move the conversations to the Bin. Defaults to false.
archiveboolAlso archive the conversations. Defaults to false.
addressstringOnly the subscriptions delivered to this address.
apiKeystring?Overrides the client's API key for this call only.
cancellationTokenCancellationTokenCancels the request.
Returns
A JsonObject with object set to domain_unsubscribe, domain, unsubscribed, skipped, failed, binned and archived.
Example
var result = await client.Subscriptions.UnsubscribeDomainAsync("news.acme.com", body: new Body { ["address"] = "me@example.com" }); Console.WriteLine($"{result["unsubscribed"]} unsubscribed, {result["skipped"]} need a person, {result["failed"]} failed");Notes
The SDK does not retry it, because a second call can send unsubscribe emails again.
Also available in
- API
POST /subscriptions/domains/{domain}/unsubscribe- TypeScript
nextmail.subscriptions.unsubscribeDomain()- Python
subscriptions.unsubscribe_domain()- Ruby
subscriptions.unsubscribe_domain- PHP
subscriptions->unsubscribeDomain- Go
Subscriptions.UnsubscribeDomain- Java
subscriptions().unsubscribeDomain- CLI
nextmail subscriptions unsubscribe-domain
Subscriptions.MoveAsync
Move what a sender sent
Task<JsonObject> MoveAsync( string id, IReadOnlyDictionary<string, object?> body, string? apiKey = null, CancellationToken cancellationToken = default)Moves every conversation from the sender to the archive, the Bin or a label, as the Subscriptions page does. destination is archive, bin or label, and label needs labelId, or the call is a 422 label_not_found.
With future, the default, a rule keeps doing it to new mail from the sender to that address, which also needs rules:write. ruleName names that rule. ["future"] = false drops a rule made that way before, when the key holds rules:write.
Parameters
idstringRequiredThe subscription, from
Subscriptions.ListAsync.destinationstringRequiredarchive,binorlabel, also inNextmail\Constants\SubscriptionDestinations.labelIdstringThe label to file under, for
label.futureboolKeep doing it to new mail with a rule. Defaults to true.
ruleNamestringA name for that rule.
apiKeystring?Overrides the client's API key for this call only.
cancellationTokenCancellationTokenCancels the request.
Returns
A JsonObject with object set to subscription_move, subscriptionId, moved and ruleId.
Example
using Nextmail.Constants; var result = await client.Subscriptions.MoveAsync("sub_7d2c1f0a9b3e4c5d6e7f8a9b", new Body{ ["destination"] = SubscriptionDestinations.Label, ["labelId"] = "newsletters", ["ruleName"] = "File Acme news",}); Console.WriteLine($"{result["moved"]} conversations moved, rule {result["ruleId"]?.ToString() ?? "none"}");Notes
The SDK retries it after a network failure, which is safe because moving the same mail again changes nothing and the rule is updated rather than added twice.
Also available in
Subscriptions.MoveManyAsync
Move what up to 100 senders sent
Task<JsonObject> MoveManyAsync( IEnumerable<string> ids, IReadOnlyDictionary<string, object?> body, string? apiKey = null, CancellationToken cancellationToken = default)Moves every conversation from each subscription in ids to the archive, the Bin or a label, the way Subscriptions.MoveAsync does for one, as Archive on a selection of the Subscriptions page does. destination is archive, bin or label, and label needs labelId, or the call is a 422 label_not_found.
With future, the default, a rule per sender keeps doing it to new mail, which also needs rules:write. moved counts the conversations moved across every sender, updated holds the subscriptions whose mail moved, failed the ones that could not be moved and missing the ids that are unknown or delivered to an address the key does not reach.
Parameters
idsIEnumerable<string>Required1 to 100 subscription ids from
Subscriptions.ListAsync. A repeated id counts once.destinationstringRequiredarchive,binorlabel, also inNextmail\Constants\SubscriptionDestinations.labelIdstringThe label to file under, for
label.futureboolKeep doing it to new mail with a rule per sender. Defaults to true.
apiKeystring?Overrides the client's API key for this call only.
cancellationTokenCancellationTokenCancels the request.
Returns
A JsonObject with object set to subscription_batch_move, moved, updated, failed and missing.
Example
using Nextmail.Constants; var result = await client.Subscriptions.MoveManyAsync(new[] { "sub_7d2c1f0a9b3e4c5d6e7f8a9b", "sub_0c3e2a91d4b7f6058e1a2b3c" }, new Body{ ["destination"] = SubscriptionDestinations.Archive, ["future"] = false,}); Console.WriteLine($"{result["moved"]} conversations archived");Notes
The SDK retries it after a network failure, which is safe because moving the same mail again changes nothing and each rule is updated rather than added twice.
Google Workspace