Prerequisites
- A Swift 5.9+ project with
ipapi-swiftadded - A free ip-api.io API key
Fast check with emailInfo
A lightweight check (no SMTP probe): validates syntax, confirms the domain has MX records, and flags disposable/throwaway providers. Use it inline on sign-up forms.
let client = IpApiClient(apiKey: ProcessInfo.processInfo.environment["IP_API_IO_KEY"]!)
let info = try await client.emailInfo(email: "user@example.com")
print(info.syntax.isValid) // true
print(info.isDisposable) // false
print(info.hasMxRecords) // true
if let record = info.mxRecords.first {
print(record.hostname)
} Full SMTP verification with validateEmail
Advanced verification that connects to the mail server to confirm the mailbox is deliverable, and adds role-account, free-provider, catch-all and Gravatar signals.
let result = try await client.validateEmail(email: "user@example.com")
print(result.reachable) // "yes" | "no" | "unknown"
if let smtp = result.smtp {
print(smtp.deliverable, smtp.catchAll)
}
print(result.disposable) // false
print(result.roleAccount) // false (e.g. info@, support@)
print(result.free) // false (e.g. gmail.com)
if let suggestion = result.suggestion {
print(suggestion) // typo fix, e.g. "user@gmail.com"
} Clean a list with validateEmailBatch
Advanced-validate up to 100 addresses in one request — the building block for email list cleaning. Throws if the array is empty or longer than 100.
let batch = try await client.validateEmailBatch(
emails: ["user@example.com", "fake@mailinator.com"])
print(batch.totalProcessed) // 2
print(batch.successfulValidations) // 2
for (email, result) in batch.results {
print(email, result.reachable, result.disposable)
}