Rust ZeroBounce API
Security
- Keep API keys on a trusted server. Do not embed them in mobile apps or browser JavaScript that untrusted users can inspect.
- Base URLs must use
https://, including theurl_providerfields you override.http://is accepted only for the hosts127.0.0.1,localhostand[::1](local tests); any otherhttp://URL is refused with an error before a connection is opened. Do not pass end-user-controlled hosts into those settings. - Request URLs include
api_keyas a query parameter (ZeroBounce API contract). Do not log full request URLs or enable payload debug logging in production.
This library is a wrapper for the ZeroBounce API v2.
For more information about the API, visit https://www.zerobounce.net/docs/.
Installation
Add the crate to Cargo.toml:
[]
= "3.0.0"
Requires Rust 1.88 or newer (rust-version = "1.88"). Upgrading from 2.x? See the
breaking changes in the 3.0.0 changelog.
How to use
This crate uses the zero-bounce API which requires an API key. Check this guide to see how to grab yours.
Check the example snippets to see how this library can be integrated in your own project.
Configuration Options
The ZeroBounce client can be configured with different base URLs depending on your region or requirements.
Default Configuration
The simplest way to create a client is using the default API URL:
use ZeroBounce;
let zb = new;
Enum Values
You can specify a region using the ApiBaseUrl enum:
use ;
// USA region
let zb = with_base_url?;
// EU region
let zb = with_base_url?;
// Default (explicit)
let zb = with_base_url?;
Custom URL String
You can also provide a custom base URL as a string:
use ZeroBounce;
let zb = with_base_url?;
with_base_url returns a ZBResult: a URL that is not https:// is an error
(http:// only for 127.0.0.1, localhost and [::1]).
Available API Base URLs:
ApiBaseUrl::Default-https://api.zerobounce.net/v2/(default)ApiBaseUrl::USA-https://api-us.zerobounce.net/v2/ApiBaseUrl::EU-https://api-eu.zerobounce.net/v2/
See the config_options example for a complete demonstration of all configuration options.
Validate options
use ZBValidateOptions;
use ZeroBounce;
let zb = new;
let options = ZBValidateOptions ;
let validation = zb.validate_email_with_options?;
// While the greylist retry is still running the API returns a message instead
// of a result; validate again in about 30 minutes to pick it up.
println!;
Inbox Placement Tester
Lives on https://bulkapi.zerobounce.net/api/ipt and spends inbox test credits.
use ;
use ZeroBounce;
let zb = new;
let providers = zb.get_inbox_placement_providers?;
let test_types = zb.get_inbox_placement_test_types?;
// test_type 1 (Email) needs sender_email; 2 is Unique ID and 3 is Auto Alias.
let created = zb.create_inbox_placement_test?;
// Send your campaign to the seeds in `created`, then read the results.
let result = zb.get_inbox_placement_test?;
let tests = zb.list_inbox_placement_tests?;
zb.set_inbox_placement_webhook?;
let webhook = zb.get_inbox_placement_webhook?;
zb.delete_inbox_placement_test?;
S3 and SFTP/FTP bulk
Queue a job on a file that already sits in your Amazon S3 bucket, or on your SFTP/FTP server. See the S3 and SFTP docs.
use ZeroBounce;
let zb = new;
// Amazon S3. file_name is the full path, as returned by list_s3_files.
// Every job takes file_name, has_header_row, remove_duplicates and return_url.
// The live API rejects a job with no return_url, so it is required here.
zb.validate_s3_file?;
zb.score_s3_file?;
zb.email_finder_s3_file?;
zb.domain_search_s3_file?;
// Export back to S3. None uses the export bucket from your ZeroBounce settings.
zb.export_s3_file?;
zb.export_s3_file?;
// SFTP/FTP. The server, path and protocol come from your ZeroBounce settings.
zb.validate_sftp_file?;
zb.score_sftp_file?;
zb.email_finder_sftp_file?;
zb.domain_search_sftp_file?;
// Note the field: this one takes export_path, not export_bucket.
// None uses the export path from your settings.
zb.export_sftp_file?;
Bulk email finder and domain search files
Run the email finder or domain search over a whole file. These four-step flows
(submit, status, download, delete) live on the bulk host without the /v2
path the other bulk APIs use. See the
bulk email finder and
domain search docs.
use ;
let zb = new;
// Email finder. domain_column is required; so is one of first_name_column or
// full_name_column — the API cannot guess a person from a domain alone.
let submitted = zb.send_email_finder_file?;
let file_id = submitted.file_id.unwrap_or_default;
zb.email_finder_file_status?;
if let Content = zb.email_finder_result_fetch?
zb.email_finder_result_delete?;
// Domain search. has_header_row is omitted when None, so the account default applies.
let submitted = zb.send_domain_search_file?;
let file_id = submitted.file_id.unwrap_or_default;
zb.domain_search_file_status?;
let results = zb.domain_search_result_fetch?;
zb.domain_search_result_delete?;
email_finder_result_fetch and domain_search_result_fetch follow the same
rules as bulk_validation_result_fetch: the file bytes come back as
ZBBulkResponse::Content, while a JSON body — including an HTTP 200 carrying
{"success": false} — is an Err with a short message.
Per-API base URLs
The list evaluator and the Inbox Placement Tester have their own base URLs,
separate from the main and bulk hosts. Overrides follow the same rule as every
other base URL: https://, or http:// only for 127.0.0.1, localhost and [::1].
use ZeroBounce;
let mut zb = new;
zb.url_provider.list_evaluator_url =
"https://bulkapi.zerobounce.net/v2/listevaluator".to_string;
zb.url_provider.inbox_placement_url =
"https://bulkapi.zerobounce.net/api/ipt".to_string;
Email Finding Methods
find_email_v2 (Recommended)
Find an email address using either a domain or company name. Uses the builder pattern for ergonomic API calls.
Requirements:
- Exactly one of
domainorcompany_namemust be provided (XOR requirement) first_nameis optional. Without it the API answers with the domain's address formats, the same asdomain_search_v2. Setting it to an empty string is still rejected.
Builder Methods:
.first_name(name: &str)- Set the first name (optional).domain(domain: &str)- Set the domain name.company_name(company: &str)- Set the company name.middle_name(name: &str)- Set the middle name (optional).last_name(name: &str)- Set the last name (optional).call()- Execute the API call
Example:
use ZeroBounce;
let zb = new;
// Using domain
let result = zb.find_email_v2
.first_name
.domain
.last_name
.call?;
// Using company name
let result = zb.find_email_v2
.first_name
.company_name
.last_name
.call?;
// With middle name
let result = zb.find_email_v2
.first_name
.domain
.middle_name
.last_name
.call?;
Returns: FindEmailResponseV2 containing:
email: The found email addressdomain: Domain nameconfidence: Email confidence level (fromemail_confidencefield)company_name: Company namedid_you_mean: Suggested alternativefailure_reason: Reason for failure if any
find_email (Deprecated)
⚠️ Deprecated since version 1.2.0 - Use find_email_v2 instead.
This method is kept for backward compatibility but will be removed in a future version. The new find_email_v2 method supports both domain and company_name parameters.
Example:
use ZeroBounce;
let zb = new;
let result = zb.find_email?;
Domain Search Methods
domain_search_v2 (Recommended)
Search for email formats using either a domain or company name. Uses the builder pattern for ergonomic API calls.
Requirements:
- Exactly one of
domainorcompany_namemust be provided (XOR requirement)
Builder Methods:
.domain(domain: &str)- Set the domain name.company_name(company: &str)- Set the company name.call()- Execute the API call
Example:
use ZeroBounce;
let zb = new;
// Using domain
let result = zb.domain_search_v2
.domain
.call?;
// Using company name
let result = zb.domain_search_v2
.company_name
.call?;
Returns: DomainSearchResponseV2 containing:
domain: Domain namecompany_name: Company nameformat: Email format foundconfidence: Confidence levelother_domain_formats: Alternative formats with confidence levelsdid_you_mean: Suggested alternativefailure_reason: Reason for failure if any
domain_search (Deprecated)
⚠️ Deprecated since version 1.2.0 - Use domain_search_v2 instead.
This method is kept for backward compatibility but will be removed in a future version. The new domain_search_v2 method supports both domain and company_name parameters.
Example:
use ZeroBounce;
let zb = new;
let result = zb.domain_search?;
Account & Usage Methods
get_credits
Get the number of credits remaining in your ZeroBounce account.
Example:
use ZeroBounce;
let zb = new;
let credits = zb.get_credits?;
println!;
Returns: i64 - The number of credits remaining in your account
get_api_usage
Get API usage statistics for a specific date range.
Arguments:
start_date: NaiveDate- Start date for the usage periodend_date: NaiveDate- End date for the usage period
Example:
use ZeroBounce;
use NaiveDate;
let zb = new;
let start = from_ymd_opt.unwrap;
let end = from_ymd_opt.unwrap;
let usage = zb.get_api_usage?;
println!;
Returns: ApiUsage containing:
total: Total number of API calls in the periodstatus_valid: Number of valid email addressesstatus_invalid: Number of invalid email addressesstatus_catch_all: Number of catch-all email addressesstatus_do_not_mail: Number of do-not-mail addressesstatus_spamtrap: Number of spamtrap addressesstatus_unknown: Number of unknown addressessub_status_antispam_system: Number of antispam system responsessub_status_greylisted: Number of greylisted responsessub_status_mail_server_temporary_error: Number of temporary mail server errorssub_status_forcible_disconnect: Number of forcible disconnectssub_status_mail_server_did_not_respond: Number of non-responsive mail serverssub_status_timeout_exceeded: Number of timeout errorssub_status_failed_smtp_connection: Number of failed SMTP connectionssub_status_mailbox_quota_exceeded: Number of mailbox quota exceeded errorssub_status_exception_occurred: Number of exceptionssub_status_possible_trap: Number of possible trapssub_status_role_based: Number of role-based addressessub_status_global_suppression: Number of globally suppressed addressessub_status_mailbox_not_found: Number of mailbox not found errorssub_status_no_dns_entries: Number of no DNS entries errorssub_status_failed_syntax_check: Number of failed syntax checkssub_status_possible_typo: Number of possible typossub_status_unroutable_ip_address: Number of unroutable IP addressessub_status_leading_period_removed: Number of leading periods removedsub_status_does_not_accept_mail: Number of addresses that don't accept mailsub_status_alias_address: Number of alias addressessub_status_role_based_catch_all: Number of role-based catch-all addressessub_status_accept_all: Number of accept-all addressessub_status_disposable: Number of disposable addressessub_status_toxic: Number of toxic addressessub_status_mx_forward,sub_status_alternate,sub_status_allowed,sub_status_blocked,sub_status_gold,sub_status_role_based_accept_all: Counts for those sub-statusesstart_date,end_date: The period the counts cover
The API returns only the counters that apply to your account and the period, so every counter is 0 when the API leaves it out.
get_api_usage_overall
Get overall API usage statistics from January 1, 2000 to the current date.
Example:
use ZeroBounce;
let zb = new;
let overall_usage = zb.get_api_usage_overall?;
println!;
Returns: ApiUsage - Same structure as get_api_usage
get_activity_data
Get activity data for a specific email address, including when it was last seen sending emails.
Arguments:
email: &str- The email address to check
Example:
use ZeroBounce;
let zb = new;
let activity = zb.get_activity_data?;
println!;
if activity.found
Returns: ActivityData containing:
found: Whether activity data was found for the emailactive_in_days:Option<u128>, the number of days within which the address was last seen active, as the API reports it;Nonewhen there is no activity data
Email Validation Methods
validate_email
Validate a single email address.
Arguments:
email: &str- The email address to validate
Example:
use ZeroBounce;
let zb = new;
let validation = zb.validate_email?;
println!;
println!;
Returns: ZBValidation containing:
address: The email address that was validatedstatus: Validation status (valid,invalid,catch-all,unknown,spamtrap,abuse,do_not_mail)sub_status: Sub-status providing more details about the validation result (validation.status_enum()/validation.sub_status_enum()give the typedZBValidateStatus/ZBValidateSubStatus)free_email: Whether the address is on a free email provideraccount: Account name (if available)domain: Domain namedid_you_mean: Suggested alternative email addressdomain_age_days: Age of the domain in daysactive_in_days,active_first_seen: Activity data (if available)smtp_provider: SMTP provider namecatchall_domain: Whether the domain is catch-all (if returned)mx_found: Whether MX records were foundmx_record: MX record valuefirstname: First name associated with the email (if available)lastname: Last name associated with the email (if available)gender: Gender associated with the email (if available)country: Country associated with the email (if available)region: Region associated with the email (if available)city: City associated with the email (if available)zipcode: Zipcode associated with the email (if available)domain_website_exists,domain_registrant_company_name: With thedomain_infooptionmessage: Set instead of a result while greylist processing is still runningprocessed_at: Timestamp when the validation was processed
validate_email_and_ip
Validate an email address with an optional IP address for more accurate validation.
Arguments:
email: &str- The email address to validateip_address: &str- Optional IP address (can be empty string)
Example:
use ZeroBounce;
let zb = new;
let validation = zb.validate_email_and_ip?;
println!;
Returns: ZBValidation - Same structure as validate_email
batch_validate
Validate multiple email addresses in a single API call. More efficient than validating emails one by one.
Arguments:
emails_and_ip_addresses: Vec<(String, String)>- Vector of tuples containing (email, ip_address) pairs. IP address can be empty string.
Example:
use ZeroBounce;
let zb = new;
let emails_and_ips = vec!;
let batch_result = zb.batch_validate?;
println!;
Returns: ZBBatchValidation containing:
email_batch: Vector ofZBValidationresults for each email addresserrors: Per-address errors (error,email_address). An account-level error (addressall, such as an invalid key or no credits) is returned asErr(ZBError::ApiError { .. })instead
Bulk Validation Methods
Bulk validation allows you to upload a file containing multiple email addresses for validation. The process involves submitting a file, checking its status, fetching results, and optionally deleting the file.
Bulk flows use the v2 bulk API. For optional v2 get file query parameters, use bulk_validation_result_fetch_with_options / ai_scoring_result_fetch_with_options with ZBGetFileOptions (download_type, and activity_data for validation only). Use zb_download_type::PHASE_1, PHASE_2, or COMBINED for download_type. For validation sendfile only, chain .set_allow_phase_2(Some(true)) or Some(false) on ZBFile to send allow_phase_2 (omitted when None); AI scoring sendfile ignores this field.
On success, bulk_validation_result_fetch / ai_scoring_result_fetch return ZBBulkResponse::Content with the file bytes. Non-success HTTP statuses and JSON error bodies (including some HTTP 200 responses with "success": false) return Err(ZBError::ApiError { status, message }) with a short message, not Feedback; ZBError::status_code() gives the HTTP status (for example 403 for a Cloudflare block, or 200 for a JSON error body). Use get_file_json_indicates_error / format_get_file_error_message from the crate root on a raw body string if you need to inspect responses yourself. ZBFileStatus includes optional file_phase_2_status when the API returns it.
bulk_validation_file_submit
Submit a file for bulk email validation.
Arguments:
zb_file: &ZBFile- AZBFileinstance containing the email addresses to validate
Example:
use ;
let zb = new;
// from_content takes the file's bytes (CSV, one address per line here).
let file_content = b"email1@example.com\nemail2@example.com\n".to_vec;
let zb_file = from_content
.set_has_header_row
.set_remove_duplicate;
let submit_result = zb.bulk_validation_file_submit?;
println!;
Returns: ZBFileFeedback containing:
success: Whether the file submission was successfulmessage: Status messagefile_name: Optional name of the submitted filefile_id: Optional file ID to use for status checks and result fetching
bulk_validation_file_status_check
Check the processing status of a submitted bulk validation file.
Arguments:
file_id: &str- The file ID returned frombulk_validation_file_submit
Example:
use ZeroBounce;
let zb = new;
let status = zb.bulk_validation_file_status_check?;
println!;
println!;
Returns: ZBFileStatus containing:
success: Whether the status check was successfulfile_id: The file IDfile_name: Name of the fileupload_date: Date when the file was uploadedfile_status: Current status of the filecomplete_percentage: Percentage of processing completederror_reason: Why the file failed, when it didfile_phase_2_status: Phase 2 status, when the API returns itreturn_url: The callback URL given at submission, if any
bulk_validation_result_fetch
Fetch the results of a completed bulk validation file. Query parameters api_key and file_id are always sent.
Arguments:
file_id: &str- The file ID returned frombulk_validation_file_submit
Example:
use ZeroBounce;
use ZBBulkResponse;
let zb = new;
let result = zb.bulk_validation_result_fetch?;
if let Content = result
Returns: Ok(ZBBulkResponse::Content(bytes)) when the response is a successful file download. JSON or JSON-shaped error responses (including some HTTP 200 cases) and HTML error pages are Err(ZBError::ApiError { .. }), carrying the HTTP status.
bulk_validation_result_fetch_with_options
Same as bulk_validation_result_fetch, plus optional v2 query parameters.
Arguments:
file_id: &stroptions: &ZBGetFileOptions— setdownload_typeand/oractivity_data(Some(true)/Some(false)).
use ;
let zb = new;
let mut opts = default;
opts.download_type = Some;
opts.activity_data = Some;
let result = zb.bulk_validation_result_fetch_with_options?;
bulk_validation_result_delete
Delete a bulk validation result file from the ZeroBounce servers.
Arguments:
file_id: &str- The file ID returned frombulk_validation_file_submit
Example:
use ZeroBounce;
let zb = new;
let delete_result = zb.bulk_validation_result_delete?;
println!;
Returns: ZBFileFeedback containing:
success: Whether the deletion was successfulmessage: Status message
AI Scoring Methods
AI Scoring allows you to upload a file containing email addresses to get AI-powered quality scores. The process is similar to bulk validation: submit a file, check status, fetch results, and optionally delete the file.
ai_scoring_file_submit
Submit a file for AI scoring analysis.
Arguments:
zb_file: &ZBFile- AZBFileinstance containing the email addresses to score
Example:
use ;
let zb = new;
// from_content takes the file's bytes (CSV, one address per line here).
let file_content = b"email1@example.com\nemail2@example.com\n".to_vec;
let zb_file = from_content
.set_has_header_row
.set_remove_duplicate;
let submit_result = zb.ai_scoring_file_submit?;
println!;
Returns: ZBFileFeedback - Same structure as bulk_validation_file_submit
ai_scoring_file_status_check
Check the processing status of a submitted AI scoring file.
Arguments:
file_id: &str- The file ID returned fromai_scoring_file_submit
Example:
use ZeroBounce;
let zb = new;
let status = zb.ai_scoring_file_status_check?;
println!;
Returns: ZBFileStatus - Same structure as bulk_validation_file_status_check
ai_scoring_result_fetch
Fetch the results of a completed AI scoring file. Same success/error rules as bulk_validation_result_fetch.
Arguments:
file_id: &str- The file ID returned fromai_scoring_file_submit
Example:
use ;
let zb = new;
let result = zb.ai_scoring_result_fetch?;
if let Content = result
ai_scoring_result_fetch_with_options
Optional download_type only; activity_data on ZBGetFileOptions is not sent for scoring getfile.
use ;
let zb = new;
let mut opts = default;
opts.download_type = Some;
let result = zb.ai_scoring_result_fetch_with_options?;
ai_scoring_result_delete
Delete an AI scoring result file from the ZeroBounce servers.
Arguments:
file_id: &str- The file ID returned fromai_scoring_file_submit
Example:
use ZeroBounce;
let zb = new;
let delete_result = zb.ai_scoring_result_delete?;
println!;
Returns: ZBFileFeedback - Same structure as bulk_validation_result_delete
Development
Run tests with Docker
From the sdk-docs/ folder in the SDKs monorepo:
Local setup and tests
# install
# run tests
# output: every suite (unit tests, offline_api, offline_warmup, mod, doc-tests)
# ends with a line like
; ; ; ;
# run examples
# WARNING: examples use live server, will consume credits
# Edit .env and set ZEROBOUNCE_API_KEY=your_api_key_here
Warmup API
The Warmup API is a separate product. It has its own host, its own team-scoped key, and its own client; your validation key will not work with it.
use ZeroBounceWarmup;
let warmup = new?;
let accounts = warmup.list_sending_accounts?;
let progress = warmup.get_progress_today?;
let csv = warmup.download_seeds?; // CSV text, columns seed,provider
Add a from-address you run yourself, with one of the five standard engagement rules (0 Default, 1 Slow Pace, 2 Repair, 3 Boost, 4 Protect):
use ;
let warmup = new?;
warmup.add_sending_account?;
A custom engagement rule can be changed only once every seven days; inside that window the API answers 429.
use ZeroBounceWarmup;
let warmup = new?;
warmup.create_custom_engagement?; // reply, important, click %
check_domain_dmarc takes an email address, not a domain — the live API rejects a bare domain even though the docs describe one:
use ZeroBounceWarmup;
let warmup = new?;
let dmarc = warmup.check_domain_dmarc?;
Every documented empty success (204, or an empty 200) comes back as Ok(None). Failures are ZBError::ApiError, whose status is reachable through ZBError::status_code(). Nothing is stored by test_smtp_configuration, and the credentials you pass it are masked out of any error it raises.
Live API suite
cargo test never touches the network: the live suite is behind the live cargo feature, so CI does not even compile it. It needs real keys, which come from the environment and are never written anywhere:
# validation API
# Warmup API
By default it only makes free calls: sandbox addresses, reads, and requests that are expected to fail but still prove the API accepts the payload. It checks that the credit balance did not move. Two flags opt in to more:
| Flag | What it adds |
|---|---|
ZEROBOUNCE_LIVE_SPEND=1 |
billable calls (scoring, activity, email finder) and a bulk round trip that deletes its own job |
ZEROBOUNCE_LIVE_CHANGES=1 |
reversible account changes — a test filter and a self-managed Warmup sending account — each undone in cleanup even when a test fails |
It never creates an Inbox Placement test, sets the Inbox Placement webhook, or starts ZB-managed Warmup onboarding, because the API cannot undo any of those.
Run it by hand before every release: the offline suite proves the SDK sends what we think it sends, and only the live suite proves the API accepts it.
Publish
- Bump
versioninCargo.toml, commit, tag (vX.Y.Z), push tag. - Actions → Publish → Run workflow with that tag.
Registry: zero-bounce on crates.io