---
title: Produce a certified-mail label
summary: Produce a SimpleCertifiedMail certified label for document distribution or subpoenas.
status: draft
owner: SAIF.Core Documentation Team
last_reviewed: 2026-09-24
library: SAIF.Services.Web.Proxies
reference_type: package
operation_id: OP-WP-08
trigger: SubpoenaLabelService and DocumentDeferredService, through the injected ISimpleCertifiedMailServiceProxy
---

# Produce a certified-mail label

`SimpleCertifiedMailServiceProxy` wraps the third-party SimpleCertifiedMail ADS SOAP service (`ADSAPISoapClient`) to size, request, and optionally save a certified-mail label image, resolving credentials from configuration unless the caller supplies them and logging any failed label response before raising it.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-WP-08 |
| **Trigger** | `SubpoenaLabelService` and `DocumentDeferredService` in SAIF.Services, through the constructor-injected `ISimpleCertifiedMailServiceProxy` |
| **Inputs** | `CertifiedLabelData`, number of pages, an optional `IsProductionMode` flag |
| **Outputs** | A Base64 GIF label image, a saved `.gif` file, or a thrown exception |
| **Primary components** | `SimpleCertifiedMailServiceProxy.GetDefaultLabelData`, `GetLabelOnly`, `SaveLabelAsGif`, `GetCertifiedLabel`, `GetModeOption` |
| **Entry point** | `Services/SAIF.Services.Web.Proxies/SimpleCertifiedMailServiceProxy.cs` |

## Steps

1. Construct `SimpleCertifiedMailServiceProxy(IEnvironmentService, ILogService)`:
   1. Guard both injected services ([WP-BR-001](../business-rules.md#wp-br-001-required-arguments-must-be-non-null-or-non-empty)).
   2. Create an HTTPS `BasicHttpBinding(Transport)` client with `int.MaxValue` quotas.
   3. Read the endpoint from `GetConfigSetting("SimpleCertifiedMailService.Url")` ([WP-BR-014](../business-rules.md#wp-br-014-simplecertifiedmail-credentials-default-from-configuration)).
2. **`GetDefaultLabelData(numberOfPages)`:** ([WP-BR-015](../business-rules.md#wp-br-015-default-label-size-is-set-by-page-count))
   1. Start with `EnvelopeSize10`, `GIF` format, and `NotifySender = false`.
   2. If pages > 10, use `Small`. If pages > 19, use `Large`.
      - If pages > 76: throw `InvalidNumberOfPagesException`.
   3. Set `GroupName = "ADMINISTRATION"`.
3. **`GetLabelOnly(data)`:** call step 5's `GetCertifiedLabel(data)` and discard the returned image ([WP-BR-016](../business-rules.md#wp-br-016-getlabelonly-discards-the-label-image)); its only effect is the remote request and any exception.
4. **`SaveLabelAsGif(data, fileName)`:**
   1. Call `GetCertifiedLabel(data)`. If the result is null, return without writing anything.
   2. Otherwise, Base64-decode the label into a `MemoryStream`, create a `Bitmap`, and save it as `fileName + ".gif"` in GIF format.
   3. The stream and bitmap are disposed in a `finally` block.
5. **`GetCertifiedLabel(data)` (private):**
   1. Build a `CertifiedLabelRequest`.
   2. Truncate `FromAddress1`, `FromAddress2`, and `ToName` to 46 characters ([WP-BR-017](../business-rules.md#wp-br-017-sender-address-and-recipient-name-are-truncated)).
   3. Default `GroupName` to `"ADMINISTRATION"`.
   4. Default `UserName`, `Password`, `ClientCode`, and `PartnerKey` to the `SimpleCertifiedMailService.*` configuration settings when the caller leaves them null ([WP-BR-014](../business-rules.md#wp-br-014-simplecertifiedmail-credentials-default-from-configuration)).
   5. Set `Mode` via `GetModeOption` (step 6).
   6. Fix `DateAdvance = 0`, `UseSL250 = false`, and `SortType = None`.
   7. Call wire `getCertifiedLabel(request)`.
      - If `StatusCode != 1`: create a `SimpleCertifiedException("SimpleCertifiedMailServiceProxy Error: {StatusMessage}")`, log it via `ILogService.LogException("SimpleCertifiedMailService", "GetCertifiedLabel", "", ex)`, and throw it ([WP-BR-018](../business-rules.md#wp-br-018-a-failed-label-response-is-logged-and-thrown)).
   8. Otherwise, return `LabelImage` (Base64).
6. **`GetModeOption(isProductionMode)`:** ([WP-BR-019](../business-rules.md#wp-br-019-label-mode-follows-the-caller-flag-or-isproduction))
   - An explicit `true` returns `production`; an explicit `false` returns `preview`.
   - When `isProductionMode` is null, the mode is `production` if `IEnvironmentService.IsProduction` is true, and `preview` otherwise.

## Process flow

The following diagram visualizes the certified-label request, including its failure path.

```mermaid
flowchart TD
	Start([GetLabelOnly / SaveLabelAsGif invoked]) --> Build["Build CertifiedLabelRequest<br>(truncate fields, default credentials)"]
	Build --> Mode["Resolve Mode via GetModeOption"]
	Mode --> Wire["Call wire getCertifiedLabel(request)"]
	Wire --> Check{"StatusCode == 1?"}
	Check -->|No| Log["Log via ILogService.LogException"] --> Throw([Throw SimpleCertifiedException])
	Check -->|Yes| Ret(["Return LabelImage, Base64"])
```

## Failure and edge-case behavior

- Requesting a label for more than 76 pages throws `InvalidNumberOfPagesException` in `GetDefaultLabelData`, before any wire call.
- A missing/invalid injected `IEnvironmentService` or `ILogService` at construction throws an argument exception.
- A non-`1` `StatusCode` in the wire response is always logged and raised as `SimpleCertifiedException`.
- `SaveLabelAsGif` returns silently, writing nothing, when `GetCertifiedLabel` returns a null label.
- Callers can bypass configuration entirely by supplying `UserName`/`Password`/`ClientCode`/`PartnerKey` directly on `CertifiedLabelData` — `DocumentDeferredService.cs` lines 112–114 do this — in which case the configuration values are not read for that request.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

## Sources
- `Services/SAIF.Services.Web.Proxies/SimpleCertifiedMailServiceProxy.cs`
- `Services/SAIF.Services.Web.Proxies/ISimpleCertifiedMailServiceProxy.cs`
