This library is a wrapper for the ZeroBounce API v2.
For more information about the API, visit https://www.zerobounce.net/docs/.
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.
The ZeroBounce client can be configured with different base URLs depending on your region or requirements.
The simplest way to create a client is using the default API URL:
use zero_bounce::ZeroBounce;
let zb = ZeroBounce::new("your_api_key");You can specify a region using the ApiBaseUrl enum:
use zero_bounce::{ZeroBounce, ApiBaseUrl};
// USA region
let zb = ZeroBounce::with_base_url("your_api_key", ApiBaseUrl::USA);
// EU region
let zb = ZeroBounce::with_base_url("your_api_key", ApiBaseUrl::EU);
// Default (explicit)
let zb = ZeroBounce::with_base_url("your_api_key", ApiBaseUrl::Default);You can also provide a custom base URL as a string:
use zero_bounce::ZeroBounce;
let zb = ZeroBounce::with_base_url("your_api_key", "https://custom-api.example.com/v2/");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.
Find an email address using either a domain or company name. Uses the builder pattern for ergonomic API calls.
Requirements:
first_nameis mandatory- Exactly one of
domainorcompany_namemust be provided (XOR requirement)
Builder Methods:
.first_name(name: &str)- Set the first name (mandatory).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 zero_bounce::ZeroBounce;
let zb = ZeroBounce::new("your_api_key");
// Using domain
let result = zb.find_email_v2()
.first_name("John")
.domain("example.com")
.last_name("Doe")
.call()?;
// Using company name
let result = zb.find_email_v2()
.first_name("John")
.company_name("Example Inc")
.last_name("Doe")
.call()?;
// With middle name
let result = zb.find_email_v2()
.first_name("John")
.domain("example.com")
.middle_name("Middle")
.last_name("Doe")
.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_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:
let result = zb.find_email("example.com", "John", "", "Doe")?;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 zero_bounce::ZeroBounce;
let zb = ZeroBounce::new("your_api_key");
// Using domain
let result = zb.domain_search_v2()
.domain("example.com")
.call()?;
// Using company name
let result = zb.domain_search_v2()
.company_name("Example Inc")
.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_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:
let result = zb.domain_search("example.com")?;Get the number of credits remaining in your ZeroBounce account.
Example:
use zero_bounce::ZeroBounce;
let zb = ZeroBounce::new("your_api_key");
let credits = zb.get_credits()?;
println!("Credits remaining: {}", credits);Returns: i64 - The number of credits remaining in your account
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 zero_bounce::ZeroBounce;
use chrono::NaiveDate;
let zb = ZeroBounce::new("your_api_key");
let start = NaiveDate::from_ymd_opt(2024, 1, 1).unwrap();
let end = NaiveDate::from_ymd_opt(2024, 1, 31).unwrap();
let usage = zb.get_api_usage(start, end)?;
println!("Total API calls: {}", usage.total);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_abuse: Number of abuse 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 addresses
Get overall API usage statistics from January 1, 2000 to the current date.
Example:
use zero_bounce::ZeroBounce;
let zb = ZeroBounce::new("your_api_key");
let overall_usage = zb.get_api_usage_overall()?;
println!("Total API calls overall: {}", overall_usage.total);Returns: ApiUsage - Same structure as get_api_usage
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 zero_bounce::ZeroBounce;
let zb = ZeroBounce::new("your_api_key");
let activity = zb.get_activity_data("[email protected]")?;
println!("Found: {}", activity.found);
if activity.found {
println!("Active status: {}", activity.active_status);
}Returns: ActivityData containing:
found: Whether activity data was found for the emailactive_status: Active status of the email addressactive_date: Date when the email was last active
Validate a single email address.
Arguments:
email: &str- The email address to validate
Example:
use zero_bounce::ZeroBounce;
let zb = ZeroBounce::new("your_api_key");
let validation = zb.validate_email("[email protected]")?;
println!("Status: {}", validation.status);
println!("Sub status: {:?}", validation.sub_status);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 resultaccount: Account name (if available)domain: Domain namedid_you_mean: Suggested alternative email addressdomain_age_days: Age of the domain in dayssmtp_provider: SMTP provider namemx_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)processed_at: Timestamp when the validation was processed
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 zero_bounce::ZeroBounce;
let zb = ZeroBounce::new("your_api_key");
let validation = zb.validate_email_and_ip("[email protected]", "99.110.204.1")?;
println!("Status: {}", validation.status);Returns: ZBValidation - Same structure as validate_email
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 zero_bounce::ZeroBounce;
let zb = ZeroBounce::new("your_api_key");
let emails_and_ips = vec![
("[email protected]".to_string(), "99.110.204.1".to_string()),
("[email protected]".to_string(), "".to_string()),
];
let batch_result = zb.batch_validate(emails_and_ips)?;
println!("Email batch: {:#?}", batch_result.email_batch);Returns: ZBBatchValidation containing:
email_batch: Vector ofZBValidationresults for each email address
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.
Submit a file for bulk email validation.
Arguments:
zb_file: &ZBFile- AZBFileinstance containing the email addresses to validate
Example:
use zero_bounce::{ZeroBounce, ZBFile};
let zb = ZeroBounce::new("your_api_key");
let file_content = vec![
"[email protected]".to_string(),
"[email protected]".to_string(),
];
let zb_file = ZBFile::from_content(file_content)
.set_has_header_row(false)
.set_remove_duplicate(true);
let submit_result = zb.bulk_validation_file_submit(&zb_file)?;
println!("File ID: {:?}", submit_result.file_id);Returns: ZBFileFeedback containing:
success: Whether the file submission was successfulmessage: Status messagefile_id: Optional file ID to use for status checks and result fetching
Check the processing status of a submitted bulk validation file.
Arguments:
file_id: &str- The file ID returned frombulk_validation_file_submit
Example:
use zero_bounce::ZeroBounce;
let zb = ZeroBounce::new("your_api_key");
let status = zb.bulk_validation_file_status_check("file_id_here")?;
println!("Complete percentage: {}%", status.complete_percentage);
println!("Success count: {}", status.success_count);Returns: ZBFileStatus containing:
success: Whether the status check was successfulmessage: Status messagefile_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 completedreturn_url: URL to fetch resultssuccess_count: Number of successfully processed emailserror_count: Number of errors encountered
Fetch the results of a completed bulk validation file.
Arguments:
file_id: &str- The file ID returned frombulk_validation_file_submit
Example:
use zero_bounce::ZeroBounce;
use zero_bounce::utility::structures::bulk::ZBBulkResponse;
let zb = ZeroBounce::new("your_api_key");
let result = zb.bulk_validation_result_fetch("file_id_here")?;
match result {
ZBBulkResponse::Content(bytes) => {
// File content (CSV format)
println!("Received {} bytes", bytes.len());
},
ZBBulkResponse::Feedback(feedback) => {
// Error or status feedback
println!("Message: {}", feedback.message);
},
}Returns: ZBBulkResponse which can be:
ZBBulkResponse::Content(Vec<u8>)- The file content as bytes (typically CSV format)ZBBulkResponse::Feedback(ZBFileFeedback)- Error or status feedback if the file is not ready or an error occurred
Delete a bulk validation result file from the ZeroBounce servers.
Arguments:
file_id: &str- The file ID returned frombulk_validation_file_submit
Example:
use zero_bounce::ZeroBounce;
let zb = ZeroBounce::new("your_api_key");
let delete_result = zb.bulk_validation_result_delete("file_id_here")?;
println!("Delete successful: {}", delete_result.success);Returns: ZBFileFeedback containing:
success: Whether the deletion was successfulmessage: Status message
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.
Submit a file for AI scoring analysis.
Arguments:
zb_file: &ZBFile- AZBFileinstance containing the email addresses to score
Example:
use zero_bounce::{ZeroBounce, ZBFile};
let zb = ZeroBounce::new("your_api_key");
let file_content = vec![
"[email protected]".to_string(),
"[email protected]".to_string(),
];
let zb_file = ZBFile::from_content(file_content)
.set_has_header_row(false)
.set_remove_duplicate(true);
let submit_result = zb.ai_scoring_file_submit(&zb_file)?;
println!("File ID: {:?}", submit_result.file_id);Returns: ZBFileFeedback - Same structure as bulk_validation_file_submit
Check the processing status of a submitted AI scoring file.
Arguments:
file_id: &str- The file ID returned fromai_scoring_file_submit
Example:
use zero_bounce::ZeroBounce;
let zb = ZeroBounce::new("your_api_key");
let status = zb.ai_scoring_file_status_check("file_id_here")?;
println!("Complete percentage: {}%", status.complete_percentage);Returns: ZBFileStatus - Same structure as bulk_validation_file_status_check
Fetch the results of a completed AI scoring file.
Arguments:
file_id: &str- The file ID returned fromai_scoring_file_submit
Example:
use zero_bounce::ZeroBounce;
use zero_bounce::utility::structures::bulk::ZBBulkResponse;
let zb = ZeroBounce::new("your_api_key");
let result = zb.ai_scoring_result_fetch("file_id_here")?;
match result {
ZBBulkResponse::Content(bytes) => {
println!("Received {} bytes", bytes.len());
},
ZBBulkResponse::Feedback(feedback) => {
println!("Message: {}", feedback.message);
},
}Returns: ZBBulkResponse - Same structure as bulk_validation_result_fetch
Delete an AI scoring result file from the ZeroBounce servers.
Arguments:
file_id: &str- The file ID returned fromai_scoring_file_submit
Example:
use zero_bounce::ZeroBounce;
let zb = ZeroBounce::new("your_api_key");
let delete_result = zb.ai_scoring_result_delete("file_id_here")?;
println!("Delete successful: {}", delete_result.success);Returns: ZBFileFeedback - Same structure as bulk_validation_result_delete
# install
sudo apt update
sudo apt install cargo rustc rustup
rustup update
rustup default stable# run tests
cargo test
cargo test find_email_v2
cargo test --release
# output
running 83 tests
test bulk::ai_scoring::test_ai_scoring_delete_not_ok ... ok
test bulk::ai_scoring::test_ai_scoring_delete_invalid_json ... ok
...
test result: ok. 83 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 5.42s# run examples
# WARNING: examples use live server, will consume credits
cp .env.sample.env .env
vi .env # set ZERO_BOUNCE_API_KEY
cargo run --example # list of available examples
cargo run --example domain_search_v2# build
cargo build --release
cargo package
# publish
cargo login <api-token>
cargo publis --dry-run
cargo publish