Inbox API
The Inbox class represents a test email inbox with methods for receiving and managing emails.
Class Overview
Section titled “Class Overview”public class InboxAn inbox has a unique email address that can receive emails. Emails are end-to-end encrypted and can only be decrypted by this inbox’s private key.
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
emailAddress | String | Full email address for this inbox |
hash | String | Unique identifier hash |
expiresAt | Instant | When the inbox expires |
serverSigPk | String | Server’s signature public key |
Getters
Section titled “Getters”public String getEmailAddress()public String getHash()public Instant getExpiresAt()public String getServerSigPk()Email Retrieval Methods
Section titled “Email Retrieval Methods”listEmails()
Section titled “listEmails()”Lists all emails in the inbox with full content.
public List<Email> listEmails()Returns: List of fully hydrated Email objects including body text, HTML, headers, attachments, links, and authentication results.
Throws:
ApiException- on API errorsNetworkException- on network connectivity issuesDecryptionException- on decryption failure
Example:
List<Email> emails = inbox.listEmails();for (Email email : emails) { System.out.println(email.getSubject()); System.out.println(email.getText()); // Full content available}listEmailsMetadataOnly()
Section titled “listEmailsMetadataOnly()”Lists all emails returning only metadata (no body content). More efficient when you only need basic email information.
public List<EmailMetadata> listEmailsMetadataOnly()Returns: List of EmailMetadata objects containing id, from, subject, receivedAt, and isRead.
Throws:
ApiException- on API errorsNetworkException- on network connectivity issuesDecryptionException- on decryption failure
Example:
List<EmailMetadata> emails = inbox.listEmailsMetadataOnly();for (EmailMetadata meta : emails) { System.out.println(meta.getId() + ": " + meta.getSubject()); if (!meta.isRead()) { // Fetch full email only if needed Email full = inbox.getEmail(meta.getId()); }}getEmail(String emailId)
Section titled “getEmail(String emailId)”Gets a specific email by ID with full content.
public Email getEmail(String emailId)Parameters:
emailId- Unique email identifier
Returns: Email with full content (body, attachments, headers, auth results)
Throws:
EmailNotFoundException- if email doesn’t existApiException- on API errorsDecryptionException- on decryption failure
Example:
Email email = inbox.getEmail("email-123");System.out.println(email.getText());System.out.println(email.getHtml());getRawEmail(String emailId)
Section titled “getRawEmail(String emailId)”Gets the raw RFC822 MIME content.
public String getRawEmail(String emailId)Parameters:
emailId- Unique email identifier
Returns: Raw email as string including all headers and MIME boundaries
Throws:
EmailNotFoundException- if email doesn’t existApiException- on API errors
Example:
String raw = inbox.getRawEmail("email-123");// Parse with javax.mail or similar libraryWait Methods
Section titled “Wait Methods”waitForEmail()
Section titled “waitForEmail()”Wait for any email to arrive.
public Email waitForEmail()public Email waitForEmail(EmailFilter filter)public Email waitForEmail(EmailFilter filter, Duration timeout)public Email waitForEmail(WaitOptions options)Parameters:
filter- Optional filter criteria (default: any email)timeout- Maximum wait time (default: from config)options-WaitOptionswith filter, timeout, and poll interval
Returns: The matching email
Throws:
TimeoutException- if no matching email arrives within timeout
Examples:
// Wait for any emailEmail email = inbox.waitForEmail();
// With filterEmail welcome = inbox.waitForEmail(EmailFilter.subjectContains("Welcome"));
// With timeoutEmail order = inbox.waitForEmail( EmailFilter.from("orders@"), Duration.ofSeconds(60));
// With full optionsEmail verification = inbox.waitForEmail( WaitOptions.builder() .filter(EmailFilter.subjectContains("Verify")) .timeout(Duration.ofSeconds(30)) .pollInterval(Duration.ofMillis(500)) .build());waitForEmailCount(int count)
Section titled “waitForEmailCount(int count)”Wait for multiple emails to arrive.
public List<Email> waitForEmailCount(int count)public List<Email> waitForEmailCount(int count, Duration timeout)Parameters:
count- Number of emails to wait fortimeout- Maximum wait time (default: from config)
Returns: List of received emails
Throws:
TimeoutException- if count not reached within timeout
Example:
// Wait for 3 emailsList<Email> emails = inbox.waitForEmailCount(3, Duration.ofSeconds(60));assertEquals(3, emails.size());awaitEmail()
Section titled “awaitEmail()”Wait for email, returning null on timeout instead of throwing exception.
public Email awaitEmail()public Email awaitEmail(EmailFilter filter)public Email awaitEmail(EmailFilter filter, Duration timeout)Parameters:
filter- Optional filter criteria (default: any email)timeout- Maximum wait time (default: from config)
Returns: The matching email, or null if timeout
Example:
Email email = inbox.awaitEmail( EmailFilter.subjectContains("Optional"), Duration.ofSeconds(10));
if (email != null) { // Process email} else { // No email received - continue without it}Subscription Methods
Section titled “Subscription Methods”onNewEmail(Consumer callback)
Section titled “onNewEmail(Consumer callback)”Subscribe to new email notifications.
public Subscription onNewEmail(Consumer<Email> callback)Parameters:
callback- Consumer called when new emails arrive
Returns: Subscription handle to unsubscribe
Example:
Subscription sub = inbox.onNewEmail(email -> { System.out.println("New email: " + email.getSubject()); email.markAsRead();});
// Later, when donesub.unsubscribe();Email Management Methods
Section titled “Email Management Methods”markEmailAsRead(String emailId)
Section titled “markEmailAsRead(String emailId)”Marks an email as read.
public void markEmailAsRead(String emailId)Parameters:
emailId- Email to mark
Throws:
EmailNotFoundException- if email doesn’t existApiException- on API errors
Note: Prefer using email.markAsRead() on the Email object.
deleteEmail(String emailId)
Section titled “deleteEmail(String emailId)”Deletes a specific email.
public void deleteEmail(String emailId)Parameters:
emailId- Email to delete
Throws:
EmailNotFoundException- if email doesn’t existApiException- on API errors
Note: Prefer using email.delete() on the Email object.
delete()
Section titled “delete()”Deletes this inbox and all its emails.
public void delete()Throws:
InboxNotFoundException- if inbox doesn’t existApiException- on API errors
Example:
// Cleanup when doneinbox.delete();Other Methods
Section titled “Other Methods”getSyncStatus()
Section titled “getSyncStatus()”Returns the synchronization status of this inbox.
public SyncStatus getSyncStatus()Returns: SyncStatus with email count and hash (useful for checking if new emails arrived)
SyncStatus Properties
Section titled “SyncStatus Properties”| Property | Type | Description |
|---|---|---|
emailCount | int | Total number of emails in the inbox |
emailsHash | String | Hash of all email IDs (changes when emails are added/removed) |
lastUpdated | String | Timestamp of last sync |
Example:
SyncStatus status = inbox.getSyncStatus();System.out.println("Email count: " + status.getEmailCount());System.out.println("Emails hash: " + status.getEmailsHash());System.out.println("Last updated: " + status.getLastUpdated());export()
Section titled “export()”Exports this inbox’s credentials for later import.
public ExportedInbox export()Returns: ExportedInbox containing credentials
Security Warning: Contains private keys - store securely!
Example:
ExportedInbox exported = inbox.export();// Equivalent to: client.exportInbox(inbox)EmailFilter Class
Section titled “EmailFilter Class”Filter for matching emails based on various criteria.
public final class EmailFilterStatic Factory Methods
Section titled “Static Factory Methods”EmailFilter.any() // Matches all emailsEmailFilter.subjectContains(String text) // Subject contains substringEmailFilter.subjectMatches(Pattern regex) // Subject matches regexEmailFilter.from(String sender) // From address contains substringEmailFilter.fromMatches(Pattern regex) // From address matches regexEmailFilter.matching(Predicate<Email> pred) // Custom predicateCombination Methods
Section titled “Combination Methods”EmailFilter filter1 = EmailFilter.subjectContains("Order");EmailFilter filter2 = EmailFilter.from("shop@");
// Combine with ANDEmailFilter combined = filter1.and(filter2);Builder Pattern
Section titled “Builder Pattern”For complex filters:
EmailFilter filter = EmailFilter.builder() .subject("Welcome") // Subject contains .from("noreply@") // From contains .subjectMatches("Order #\\d+") // Subject matches regex .fromMatches(Pattern.compile(".*@example\\.com")) .where(email -> email.getAttachments().size() > 0) // Custom predicate .build();Builder Methods
Section titled “Builder Methods”| Method | Description |
|---|---|
subject(String) | Subject contains substring |
subjectMatches(String) | Subject matches regex string |
subjectMatches(Pattern) | Subject matches regex pattern |
from(String) | From address contains substring |
fromMatches(String) | From address matches regex string |
fromMatches(Pattern) | From address matches regex pattern |
where(Predicate<Email>) | Custom predicate |
Filter Examples
Section titled “Filter Examples”// Simple - subject containsEmailFilter.subjectContains("Password Reset")
// Simple - from address
// Regex patternEmailFilter.subjectMatches(Pattern.compile("Invoice #\\d+"))
// Combined filtersEmailFilter.subjectContains("Order") .and(EmailFilter.from("shop@")) .and(EmailFilter.matching(e -> e.getAttachments().size() > 0))
// Custom predicateEmailFilter.matching(email -> { return email.getLinks().stream() .anyMatch(link -> link.contains("/verify"));})WaitOptions Class
Section titled “WaitOptions Class”Configuration for wait operations.
public final class WaitOptionsBuilder
Section titled “Builder”WaitOptions options = WaitOptions.builder() .filter(EmailFilter.subjectContains("Reset")) .timeout(Duration.ofSeconds(30)) .pollInterval(Duration.ofSeconds(1)) .build();Properties
Section titled “Properties”| Property | Type | Default | Description |
|---|---|---|---|
filter | EmailFilter | any() | Filter criteria |
timeout | Duration | from config | Maximum wait time |
pollInterval | Duration | from config | Poll frequency (polling strategy) |
EmailMetadata Class
Section titled “EmailMetadata Class”Lightweight representation of an email containing only metadata (no body content).
public class EmailMetadataProperties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
id | String | Unique email identifier |
from | String | Sender’s email address |
subject | String | Email subject line |
receivedAt | String | When the email was received |
isRead | boolean | Whether the email has been marked as read |
Getters
Section titled “Getters”public String getId()public String getFrom()public String getSubject()public String getReceivedAt()public boolean isRead()Example
Section titled “Example”List<EmailMetadata> emails = inbox.listEmailsMetadataOnly();for (EmailMetadata meta : emails) { System.out.printf("[%s] %s - %s%n", meta.isRead() ? "READ" : "NEW", meta.getFrom(), meta.getSubject());}Subscription Interface
Section titled “Subscription Interface”Handle for managing email subscriptions.
@FunctionalInterfacepublic interface Subscription { void unsubscribe();}Methods
Section titled “Methods”| Method | Description |
|---|---|
unsubscribe() | Stops the subscription |
Example:
Subscription sub = inbox.onNewEmail(email -> { processEmail(email);});
// When done listeningsub.unsubscribe();Complete Examples
Section titled “Complete Examples”Basic Email Retrieval
Section titled “Basic Email Retrieval”Inbox inbox = client.createInbox();System.out.println("Send emails to: " + inbox.getEmailAddress());
// Wait for emailEmail email = inbox.waitForEmail();
// ProcessSystem.out.println("From: " + email.getFrom());System.out.println("Subject: " + email.getSubject());System.out.println("Body: " + email.getText());
// Cleanupinbox.delete();Filtered Waiting
Section titled “Filtered Waiting”// Wait for password reset emailEmail resetEmail = inbox.waitForEmail( EmailFilter.subjectContains("Password Reset") .and(EmailFilter.from("noreply@")), Duration.ofSeconds(30));
// Extract reset linkString resetLink = resetEmail.getLinks().stream() .filter(l -> l.contains("/reset")) .findFirst() .orElseThrow(() -> new AssertionError("No reset link found"));
System.out.println("Reset link: " + resetLink);Real-Time Subscription
Section titled “Real-Time Subscription”List<Email> received = new CopyOnWriteArrayList<>();
Subscription sub = inbox.onNewEmail(email -> { System.out.println("Received: " + email.getSubject()); received.add(email);
if (email.getSubject().contains("Urgent")) { notifyAdmin(email); }
email.markAsRead();});
// Trigger emails to be sent...
// Wait for expected emailsThread.sleep(5000);
// Stop listeningsub.unsubscribe();
System.out.println("Received " + received.size() + " emails");Multiple Emails
Section titled “Multiple Emails”// Wait for 3 confirmation emailsList<Email> confirmations = inbox.waitForEmailCount(3, Duration.ofSeconds(60));
// Verify all receivedassertEquals(3, confirmations.size());
// Process eachfor (Email email : confirmations) { assertTrue(email.getSubject().contains("Confirmation")); processConfirmation(email);}Optional Email (No Exception)
Section titled “Optional Email (No Exception)”// Check for optional notificationEmail notification = inbox.awaitEmail( EmailFilter.subjectContains("Notification"), Duration.ofSeconds(5));
if (notification != null) { System.out.println("Got notification: " + notification.getSubject());} else { System.out.println("No notification received (expected in some cases)");}Export and Import
Section titled “Export and Import”// Export inbox for later useExportedInbox exported = inbox.export();saveToFile(exported);
// Later, import in another sessionExportedInbox loaded = loadFromFile();Inbox restoredInbox = client.importInbox(loaded);
// Continue using the inboxEmail email = restoredInbox.waitForEmail();Thread Safety
Section titled “Thread Safety”The Inbox class is thread-safe:
- Multiple threads can call methods simultaneously
- Email lists are safely copied
- Subscriptions are thread-safe
- Wait operations can be called from different threads
Related Pages
Section titled “Related Pages”- VaultSandboxClient API - Creating inboxes
- Email API - Email class reference
- Waiting for Emails - Wait patterns
- Real-time Subscriptions - Subscription patterns