Skip to main content

Crate yopmail_client

Crate yopmail_client 

Source
Expand description

Unofficial async client for YOPmail.

yopmail-client drives the same HTTP endpoints as the YOPmail web UI to:

  • list inbox messages
  • fetch message content (text/HTML/raw) and attachments
  • generate and fetch RSS feeds
  • send messages (currently only to @yopmail.com)

This crate is not affiliated with YOPmail. The YOPmail site is HTML-driven and may change at any time; parsing is best-effort and may break without warning.

Quick start

use yopmail_client::{generate_random_mailbox, YopmailClient};

#[tokio::main]
async fn main() -> Result<(), yopmail_client::Error> {
    // A mailbox can be provided as `local` or `local@domain`.
    // Generating a random mailbox helps avoid collisions in shared inbox namespaces.
    let mailbox = generate_random_mailbox(12);
    let mut client = YopmailClient::new(&mailbox)?;

    // Establish a session (cookies + `yp` token). Most methods do this lazily, but calling it
    // explicitly makes the stateful behavior obvious.
    client.open_inbox().await?;

    // Page numbers are passed through to YOPmail as-is (typically page 1 is the newest).
    let messages = client.list_messages(1).await?;
    if let Some(msg) = messages.first() {
        // Use the `Message::id` returned by `list_messages`.
        let content = client.fetch_message_full(&msg.id).await?;
        println!("{}", content.text);
    }
    Ok(())
}

Notes for experienced users

  • The client is stateful: it keeps a cookie jar and an extracted yp token. Methods take &mut self because the session state is updated on demand.
  • Message::date is currently always None because the inbox HTML parser does not extract it.
  • Network calls are performed with reqwest; non-2xx HTTP responses are typically surfaced as Error::Status, with the response body captured for debugging.
  • There is no built-in polling loop. Convenience methods like YopmailClient::check_inbox perform a single request; if you want to poll, implement a loop with tokio::time::sleep.

Error behavior

Re-exports§

pub use client::generate_random_mailbox;
pub use client::YopmailClient;
pub use client::YopmailClientBuilder;
pub use constants::default_headers;
pub use constants::default_timeout;
pub use constants::ALT_DOMAINS;
pub use constants::DEFAULT_DOMAIN;
pub use constants::DEFAULT_HEADERS;
pub use constants::DEFAULT_TIMEOUT_SECS;
pub use error::Error;
pub use models::Attachment;
pub use models::Message;
pub use models::MessageContent;
pub use models::RssItem;

Modules§

client
High-level async client for interacting with YOPmail via its web endpoints.
constants
HTTP and protocol constants used to emulate the YOPmail web UI.
error
Error types for this crate.
models
Data models returned by YOPmail operations.