Skip to content

About

Official ZeroBounce Pascal/Delphi SDK: email validation, AI scoring, bulk files, email finder and domain search

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Zero bounce API - pascal SDK

Requirements

  • Free Pascal 3.2 with the FCL units (fp-units-fcl, fp-units-base). CI and the test image build with FPC 3.2.2; earlier releases are not tested.
  • FPC builds: the OpenSSL shared libraries (CI installs libssl-dev) and trusted CA certificates, since TLS is verified - see TLS certificates below.
  • Delphi: a version whose System.Net.HttpClient THTTPClient has ConnectionTimeout, ResponseTimeout and HandleRedirects. Delphi builds use the operating system's TLS stack. They are not compiled in CI, so no minimum Delphi version has been verified.

Security

  • Keep API keys on a trusted server. Do not embed them in mobile apps or browser JavaScript that untrusted users can inspect.
  • Custom API base URLs (when supported) must use https://. Do not pass end-user-controlled hosts into those settings.
  • Request URLs include api_key as a query parameter (ZeroBounce API contract). Do not log full request URLs or enable payload debug logging in production.
  • Redirects are never followed: a 3xx answer raises a ZbException carrying its status. Every request has a connect and a read timeout, ZbConnectTimeoutMs (default 30000) and ZbReadTimeoutMs (default 120000), in milliseconds.
  • Trailing slashes on any base URL variable (ZbApiBaseURL, BULK_URI, ZbBulkRootURL, ZbListEvaluatorURL, ZbInboxPlacementURL, ZbWarmupBaseURL) are dropped when a request is built, so no request path contains //.
  • A timeout of zero or less is refused before anything is sent: ZbConnectTimeoutMs and ZbReadTimeoutMs must be greater than 0, or the call raises ZbException (ZbConnectTimeoutMs must be greater than 0, ZbReadTimeoutMs must be greater than 0).
  • A URL the SDK sends to (every base URL, and so the whole request) is refused before sending when it holds a backslash, whitespace, a control or invisible character, bytes that are not valid UTF-8, or a non-ASCII character or a % in the host; when it has user information (user@host), a query string or a fragment (?, #) in a base URL; or when it is neither https:// nor plain http:// to exactly 127.0.0.1, localhost or [::1]. The URL itself is never quoted in the message, since it may carry a credential.
  • A Warmup download target (the path given to ZbWarmupDownloadSeeds or ZbWarmupDownloadStatistics) is checked before the request is sent: a path whose last component is empty (it ends in a path separator), . or .., or that names an existing directory, raises Could not write <path>. The file is written to a temporary file beside the target and moved into place, so a failed write leaves a file already there as it was; a symbolic link at the path is written through to the file it points at (a cycle, or more than 40 links, raises and leaves the link alone); the permission bits of a file being replaced are kept, and the temporary file is created with those bits before any data is written. The target's directory is created only once there is something to write.

This library is a wrapper for the ZeroBounce API v2.

For more information about the API, visit https://www.zerobounce.net/docs/.

This library calls the ZeroBounce API, which requires an API key. Check this guide to see how to grab yours.

The API key is per thread: call ZBInitialize on every thread that makes requests.

TLS certificates (Free Pascal builds)

Since 2.2.0, FPC builds verify the server's TLS certificate and host name, so they need trusted CA certificates. Breaking for 2.1.3 users: 2.1.3 did not verify at all. The SDK looks, in order, at:

  1. ZbCACertFile (unit ZbUtility), the full path of a PEM CA bundle;
  2. the SSL_CERT_FILE environment variable;
  3. on Linux, macOS and other Unix systems, the usual bundle paths (/etc/ssl/certs/ca-certificates.crt, /etc/pki/tls/certs/ca-bundle.crt, /etc/ssl/ca-bundle.pem, /etc/ssl/cert.pem);
  4. cacert.pem beside the executable;
  5. on Windows, the Windows "ROOT" system certificate store.

If none of them yields a certificate, every request raises a ZbException that says so; a ZbCACertFile or SSL_CERT_FILE naming a file that does not exist raises as well. Verification is never switched off. On Windows, with nothing configured, the SDK uses the certificates in the Windows "ROOT" store. If requests still raise (for example on a machine whose store lacks the root that ZeroBounce's certificate chains to), download a PEM bundle such as https://curl.se/ca/cacert.pem and either save it as cacert.pem next to your .exe, or point the SDK at it before the first request:

uses ZbUtility;

begin
    ZbCACertFile := 'C:\MyApp\cacert.pem';
    ZBInitialize('YOUR__API__KEY');
end.

Keep the bundle up to date. Delphi builds use the operating system's TLS stack and ignore ZbCACertFile.

Package's units

The methods implemented in this library can raise ZbException.

  • ZbUtility - contains utility methods
    • ZBInitialize - set the API key (and API base URL) to be used within the all SDK's methods
          // ApiURL can be ZbApiURLDefault, ZbApiURLUSA, ZbApiURLEU
          ZBInitialize('YOUR__API__KEY', ZbApiURLDefault);
      
          // or an explicit base URL, for a region the enum does not name
          // or for a local stub. https only - plain http only when the
          // host is exactly 127.0.0.1, localhost or [::1] - and a
          // trailing slash is dropped.
          ZBInitialize('YOUR__API__KEY', 'https://api-au.zerobounce.net/v2');
    • ZbException - exception containing data about the response context
  • ZbGeneric - contains general purpose methods
    • ZbGetCredits (returns integer) - fetch account's credits
    • ZbGetApiUsage (returns TApiUsage) - fetch account's (overall or specific) API usage
    • ZbActivityData (returns integer) - fetch the amount of days an email inbox has been active
    • ZbFindEmailByDomain (returns TZbFindEmailResponse) - identifies and validates a person’s primary email address via domain
    • ZbFindEmailByCompanyName (returns TZbFindEmailResponse) - identifies and validates a person’s primary email address via company name
    • ZbDomainSearchByDomain (returns TZbDomainSearchResponse) - detects possible email address patterns used by a domain
    • ZbDomainSearchByCompanyName (returns TZbDomainSearchResponse) - detects possible email address patterns used by a company
    • ZbScoreEmail / ZbScoreEmailPost (return TZbScoreEmailResult) - real-time AI scoring over GET or POST
  • ZbValidation - fetch validation information about emails
    • ZbValidateEmail (returns TZbValidationResult) - validate one email
    • ZbBatchValidateEmails (returns TZBBatchValidation) - validate a list of emails
  • ZbBulk - bulk email validation or AI scoring (bulk base URL: https://bulkapi.zerobounce.net/v2; see v2 send file, v2 file status, v2 get file)
    • TZbBulkParams - column indexes and flags for file submit; set AllowPhase2Specified and AllowPhase2 to send allow_phase_2 on validation sendfile only (not AI scoring), and RemoveDuplicate for remove_duplicate, which is always sent (as in 3.0.x; False in a zero-filled record; RemoveDuplicateSpecified has no effect). ReturnUrl, last in the record, is sent as return_url when it is not empty.
    • TZbGetFileOptions / PTZbGetFileOptions - optional download_type (DownloadType) and validation-only activity_data (ActivityDataSpecified + ActivityData); pass @Options as the second argument to ZbBulkValidationResultFetch and ZbAiScoringResultFetch, or nil for defaults. The email-finder and domain-search result fetches take only the file id.
    • Constants in ZbUtility: ZB_DOWNLOAD_TYPE_PHASE_1, ZB_DOWNLOAD_TYPE_PHASE_2, ZB_DOWNLOAD_TYPE_COMBINED.
    • Bulk Email validation:
      • ZbBulkValidationFileSubmit (returns TZBFileFeedback) - submit for bulk validation a file contents, containing emails
      • ZbBulkValidationFileStatusCheck (returns TZBFileStatus) - check the status of a submitted file
      • ZbBulkValidationResultFetch (returns TZBBulkResponse) - fetch the validation result; optional Options: PTZbGetFileOptions = nil
      • ZbBulkValidationResultDelete (returns TZBFileFeedback) - delete file submitted for bulk validation
    • AI scoring:
      • ZbAiScoringFileSubmit (returns TZBFileFeedback) - submit for AI scoring a file contents, containing emails
      • ZbAiScoringFileStatusCheck (returns TZBFileStatus) - check the status of a submitted file
      • ZbAiScoringResultFetch (returns TZBBulkResponse) - fetch the scoring result; optional Options: PTZbGetFileOptions = nil (activity_data is not sent for scoring getfile)
      • ZbAiScoringResultDelete (returns TZBFileFeedback) - delete file submitted for AI scoring
    • For getfile (here and in the email finder / domain search result fetches), a JSON body - a JSON object or list, including one behind white space, a byte-order mark or a no-break space, or any body served as application/json, text/json or a +json type in any letter case - raises a ZbException whose StatusCode is the HTTP status, 200 included. An empty body, a body of only that padding, and an HTML page raise as well. Otherwise HasContent is true and Content holds the file text. A response with no Content-Type header raises Http Error: No headers found in response.
  • ZbPriority3 - bulk email finder and domain search, filters, the list evaluator, the S3 / SFTP bulk jobs and the Inbox Placement Tester
    • Bulk email finder and domain search, on the bulk root (https://bulkapi.zerobounce.net, no /v2): ZbSendEmailFinderFile, ZbEmailFinderFileStatus, ZbEmailFinderResultFetch, ZbEmailFinderResultDelete, and the matching ZbSendDomainSearchFile / ZbDomainSearch... functions. ZbSendEmailFinderFile needs DomainColumn and one of FirstNameColumn / FullNameColumn; with neither name column the job has nothing to build a local part from, so it is refused before the upload
    • List evaluator: ZbSendListEvaluatorFile, ZbGetListEvaluatorResult and ZbSendEvaluatedFile(FileId), all three built from their own base URL, ZbListEvaluatorURL (send-evaluated-file/ sits beside it). ZbSendEvaluatedFile sends the file id as a form field, not as a path segment
    • Filters: ZbAddFilter(Rule, Target, Value), ZbListFilters(UsePost), ZbDeleteFilter(Rule, Target, Value). Rule is allow or block; Target is email, domain, mx or tld. Both are checked before the request is sent.
    • S3 / SFTP jobs: ZbListS3Files, ZbValidateS3File, ZbScoreS3File, ZbExportS3File, ZbEmailFinderS3File, ZbDomainSearchS3File, ZbValidateSFTPFile, ZbScoreSFTPFile, ZbEmailFinderSFTPFile, ZbDomainSearchSFTPFile, ZbExportSFTPFile. TZbBulkFileJobOptions requires both FileName and ReturnUrl — the live API rejects a job without either, validateSFTPfile included, although the docs call its file_name optional. ZbExportSFTPFile sends export_path, not the export_bucket that ZbExportS3File sends. TZbValidateS3FileOptions and TZbScoreS3FileOptions require FileName and ReturnUrl for the same reason; they keep their own records because they also carry EmailAddressColumn and, for validate, the name, gender and IP columns.
    • Inbox Placement Tester (its own host, ZbInboxPlacementURL): ZbInboxPlacementProviders, ZbInboxPlacementTestTypes, ZbCreateInboxPlacementTest, ZbInboxPlacementTest, ZbListInboxPlacementTests, ZbDeleteInboxPlacementTest, ZbInboxPlacementWebhook, ZbSetInboxPlacementWebhook. It authenticates with an Authorization: Bearer header, takes camelCase JSON bodies, and lists tests from GET /tests. These calls spend the account's inbox-test credits. Each returns the raw JSON body; ZbDeleteInboxPlacementTest returns an empty string for the API's empty answer to a delete, and an empty 2xx from any other of these calls raises a ZbException with the HTTP status.
      • ZbCreateInboxPlacementTest(Name, Options) - Name is capped at 64 Unicode characters, not bytes, TestType is 1, 2 or 3, and type 1 (the one you send yourself) needs a SenderEmail. Pick the mailboxes with ProviderIds, SeedIds or Providers (an array of { Id, MaxSeeds }); an empty array is left out of the body and the account default applies
      • ZbListInboxPlacementTests(Options) - Status is running or finished, PageSize is 1-100, and CreatedAfter / CreatedBefore filter by time. The page size goes out as page_size: spelled pageSize the API accepts it and then silently ignores it, so the filter looks like it worked until you count the rows
  • ZbWarmup - the Warmup API, a separate product with its own host and its own team-scoped key
    • ZbWarmupInitialize('YOUR__WARMUP__API__KEY') - the key goes out in an API-Key header. It is not the validation key, and ZBInitialize stays for that one. The Warmup key is per thread, as the validation key is.
    • Every function returns the raw JSON body, or an empty string for a zero-byte 2xx (HTTP 204 and an empty 200 included).
    • Sending accounts: ZbWarmupListSendingAccounts, ZbWarmupGetSendingAccount, ZbWarmupAddSendingAccount, ZbWarmupUpdateSendingAccount, ZbWarmupDeleteSendingAccount, ZbWarmupChangeFromAddress, ZbWarmupListFromAddresses
    • Engagement rules: ZbWarmupGetEngagementRules, ZbWarmupSetEngagementRule, ZbWarmupGetCustomEngagement, ZbWarmupCreateCustomEngagement, ZbWarmupUpdateCustomEngagement, ZbWarmupDeleteCustomEngagement. A standard rule is 0 to 4; a custom rule takes reply_pct 5-45, important_pct 5-40 and click_pct 0-70 and at most important_pct x 1.75, all checked before sending.
    • Seeds, progress and statistics: ZbWarmupGetSeeds, ZbWarmupDownloadSeeds, ZbWarmupGetSeedCount, ZbWarmupGetProgressToday, ZbWarmupGetSentToday, ZbWarmupGetEmailsPerDay, ZbWarmupGetStatistics, ZbWarmupGetStatisticsPerDay, ZbWarmupGetStatisticsDetailed, ZbWarmupDownloadStatistics, ZbWarmupGetFromAddressStatistics. The two download functions return CSV text and save it as well when given a path.
    • Deliverability: ZbWarmupCheckDomainDmarc(FromAddress[, DkimSelector]) takes an email address, not a bare domain, which is what the live API requires; ZbWarmupTestSmtpConfiguration stores nothing and answers a failed SMTP login with HTTP 500.
  • ZbStructures - contains structures returned by the methods enumerated above (TZbFileStatus includes FilePhase2Status / file_phase_2_status when the API returns it)

Usage

Delphi

In order to run this package, one must install Delphi IDE.

Open Delphi IDE, File > Open, browse for ./packages/ZeroBounce.dpk (or ./packages/zb.groupproj), click "Open package".

Minimal Delphi example (no package): For a self-contained single-email validation example using Delphi's built-in System.Net.HttpClient (no OpenSSL DLLs; no minimum Delphi version has been verified), see examples/delphi-api-v2/. Build ValidateEmailExample.dpr there; no SDK package install required.

In order to run example snippets or your own project using the zero-bounce package, first install the package into Delphi:

  • open package (described above)
  • locate projects window (or CTRL+ALT+F11)
  • right click on the project ("ZeroBounce.bpl") > Compile
  • right click on the project > Install

After installing, the example projects (./examples/delphi/Examples.groupproj) should run successfully. If that still doesn't happen, follow the steps below.

To run the ZeroBounce SDK with any other Dephi project:

  • open desired project
  • Project > Options (or SHIFT+CTRL+F11) > Packages > Runtime Packages
  • enable "Link with runtime packages"
  • [optional] click on the three dots from "Runtime packages", browse to C:\Users\Public\Documents\Embarcadero\Studio\{INSTALLED VERSION}\Bpl, select "Any file (.)" from bottom-right, select ZeroBounce.bpl file
  • you can now import project's units

Free Pascal

In order to run this package, one must install Lazarus IDE.

Open Lazarus IDE, File > Open, browse for ./packages/zerobounce.lpk (relative to repository root), click "Open package".

In order to run unit tests, example snippets or your own project with the zero-bounce package, first install it into lazarus:

  • open package (described above)
  • locate package window (titled with "Package ZeroBounce {version}")
  • Compile
  • Use > Install

After installing, opening either tests (./tests/unit_tests.lpi) or example snippets (any *.lpi file from ./examples/fpc/ folder) should work running.

To run ZeroBounce SDK with any other FPC project:

  • open desired project
  • Project > Project inspector > Add > New requirement
  • pick "ZeroBounce" from the list
  • it should now appear in "Required Packages"
  • you can now import project's units

Testing

Unit tests (FPCUnit) can be run via Docker or locally.

Docker: from the repository root (the image builds the console runner; running it runs the suite):

docker build -t zerobounce-pascal-sdk:test .
docker run --rm --network none zerobounce-pascal-sdk:test

The repository includes a .dockerignore to keep the image build context small.

Local (console): with FPC and fp-units-fcl installed, the same commands CI runs (.github/workflows/sdk_ci.yml): fpc -Fu./src -Fu./tests -Mobjfpc -O2 -gl -viwn tests/unit_tests_console.lpr -FE. then ./unit_tests_console --all.

Local (GUI): open tests/unit_tests.lpr in Lazarus and run (Run → Run).

The offline suite never reaches the live API. live/live_api.lpr is a separate, opt-in live suite; see the comments at its top for the environment variables it reads.

Publish

  1. Bump the version in every file that carries it, commit, tag (vX.Y.Z), push tag (maintainers: sdk-docs/scripts/check-untagged-bump-and-push.sh in the SDKs workspace updates all three):

    • packages/zerobounce.lpk (<Version Major= Minor= Build=>, the version of record);
    • packages/ZeroBounce.dpk ({$LIBVERSION 'X.Y.Z'});
    • packages/ZeroBounce.dproj (every <DllVersion>, and FileVersion and ProductVersion as X.Y.Z.0).

    sh .github/scripts/check-package-versions.sh fails when they disagree (CI and the Publish workflow run it). It also fails when a src/*.pas unit is missing from the .dpk, .dproj, .lpk or packages/zerobounce.pas, or a src/*.inc from the .lpk; a commented-out entry does not count.

  2. Actions → Publish → Run workflow with that tag.

No package registry — GitHub release only. Pin the tag via clone or submodule.

License

MIT. See LICENSE.

About

Official ZeroBounce Pascal/Delphi SDK: email validation, AI scoring, bulk files, email finder and domain search

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages