Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

Async client for GuerrillaMail temporary email service.

Implementations§

Source§

impl Client

Source

pub fn builder() -> ClientBuilder

Create a builder for configuring the client.

Source

pub async fn new() -> Result<Self>

Create a new GuerrillaMail client.

Connects to GuerrillaMail and retrieves the API token and available domains.

Examples found in repository?
examples/demo.rs (line 24)
14async fn main() -> Result<(), Box<dyn std::error::Error>> {
15    println!("📧 GuerrillaMail Rust Client - Full Demo");
16    println!("{}", "=".repeat(50));
17
18    // =========================================
19    // 1. Create client (optionally with proxy)
20    // =========================================
21    println!("\n🔌 Creating client...");
22
23    // Without proxy:
24    let client = Client::new().await?;
25
26    // With proxy (uncomment to use):
27    // let client = Client::builder().proxy("http://127.0.0.1:8080").build().await?;
28
29    // Custom configuration example (uncomment to use):
30    // let client = Client::builder()
31    //     .proxy("http://127.0.0.1:8080")
32    //     .danger_accept_invalid_certs(false)
33    //     .user_agent("guerrillamail-demo/1.0")
34    //     .ajax_url("https://www.guerrillamail.com/ajax.php")
35    //     .build()
36    //     .await?;
37
38    println!("   ✅ Connected to GuerrillaMail API");
39
40    // =========================================
41    // 2. Create temporary email address
42    // =========================================
43    println!("\n📬 Creating temporary email...");
44    let alias = format!("demo{}", rand::random::<u16>());
45    let email = client.create_email(&alias).await?;
46    println!("   ✅ Created: {}", email);
47
48    // =========================================
49    // 3. Poll for messages (get_messages)
50    // =========================================
51    println!("\n⏳ Waiting for messages...");
52    println!("   Send an email to: {}", email);
53    println!("   (Polling for up to 2 minutes)");
54
55    let start = std::time::Instant::now();
56    let timeout = std::time::Duration::from_secs(120);
57    let poll_interval = std::time::Duration::from_secs(5);
58
59    loop {
60        // get_messages returns basic info: id, from, subject, excerpt
61        let messages = client.get_messages(&email).await?;
62
63        if !messages.is_empty() {
64            println!("\n\n📥 Received {} message(s)!", messages.len());
65
66            for msg in &messages {
67                println!("\n{}", "-".repeat(50));
68                println!("Message ID:  {}", msg.mail_id);
69                println!("From:        {}", msg.mail_from);
70                println!("Subject:     {}", msg.mail_subject);
71                println!(
72                    "Excerpt:     {}",
73                    &msg.mail_excerpt[..msg.mail_excerpt.len().min(80)]
74                );
75                println!("Timestamp:   {}", msg.mail_timestamp);
76
77                // =========================================
78                // 4. Fetch full email content (fetch_email)
79                // =========================================
80                println!("\n📄 Fetching full email body...");
81                match client.fetch_email(&email, &msg.mail_id).await {
82                    Ok(details) => {
83                        println!("   Body length: {} characters", details.mail_body.len());
84                        println!("   Preview (first 500 chars):");
85                        println!("   {}", "-".repeat(40));
86                        let preview: String = details.mail_body.chars().take(500).collect();
87                        for line in preview.lines().take(10) {
88                            println!("   {}", line);
89                        }
90                        if details.mail_body.len() > 500 {
91                            println!("   ... (truncated)");
92                        }
93                    }
94                    Err(e) => {
95                        eprintln!("   ❌ Failed to fetch: {}", e);
96                    }
97                }
98            }
99            break;
100        }
101
102        if start.elapsed() >= timeout {
103            println!("\n\n⚠️  Timeout: No messages received");
104            break;
105        }
106
107        let remaining = (timeout - start.elapsed()).as_secs();
108        print!("\r   Checking... {} seconds remaining   ", remaining);
109        use std::io::Write;
110        std::io::stdout().flush().ok();
111
112        tokio::time::sleep(poll_interval).await;
113    }
114
115    // =========================================
116    // 5. Delete/forget email address
117    // =========================================
118    println!("\n🗑️  Cleaning up email address...");
119    match client.delete_email(&email).await {
120        Ok(true) => println!("   ✅ Email address deleted"),
121        Ok(false) => println!("   ⚠️  Deletion may have failed"),
122        Err(e) => eprintln!("   ❌ Error: {}", e),
123    }
124
125    println!("\n{}", "=".repeat(50));
126    println!("✨ Demo complete!");
127
128    Ok(())
129}
Source

pub fn proxy(&self) -> Option<&str>

Get the proxy URL if one was configured.

Source

pub async fn create_email(&self, alias: &str) -> Result<String>

Create a temporary email address.

§Arguments
  • alias - The email alias (part before @)
§Returns

The full email address assigned by GuerrillaMail

Examples found in repository?
examples/demo.rs (line 45)
14async fn main() -> Result<(), Box<dyn std::error::Error>> {
15    println!("📧 GuerrillaMail Rust Client - Full Demo");
16    println!("{}", "=".repeat(50));
17
18    // =========================================
19    // 1. Create client (optionally with proxy)
20    // =========================================
21    println!("\n🔌 Creating client...");
22
23    // Without proxy:
24    let client = Client::new().await?;
25
26    // With proxy (uncomment to use):
27    // let client = Client::builder().proxy("http://127.0.0.1:8080").build().await?;
28
29    // Custom configuration example (uncomment to use):
30    // let client = Client::builder()
31    //     .proxy("http://127.0.0.1:8080")
32    //     .danger_accept_invalid_certs(false)
33    //     .user_agent("guerrillamail-demo/1.0")
34    //     .ajax_url("https://www.guerrillamail.com/ajax.php")
35    //     .build()
36    //     .await?;
37
38    println!("   ✅ Connected to GuerrillaMail API");
39
40    // =========================================
41    // 2. Create temporary email address
42    // =========================================
43    println!("\n📬 Creating temporary email...");
44    let alias = format!("demo{}", rand::random::<u16>());
45    let email = client.create_email(&alias).await?;
46    println!("   ✅ Created: {}", email);
47
48    // =========================================
49    // 3. Poll for messages (get_messages)
50    // =========================================
51    println!("\n⏳ Waiting for messages...");
52    println!("   Send an email to: {}", email);
53    println!("   (Polling for up to 2 minutes)");
54
55    let start = std::time::Instant::now();
56    let timeout = std::time::Duration::from_secs(120);
57    let poll_interval = std::time::Duration::from_secs(5);
58
59    loop {
60        // get_messages returns basic info: id, from, subject, excerpt
61        let messages = client.get_messages(&email).await?;
62
63        if !messages.is_empty() {
64            println!("\n\n📥 Received {} message(s)!", messages.len());
65
66            for msg in &messages {
67                println!("\n{}", "-".repeat(50));
68                println!("Message ID:  {}", msg.mail_id);
69                println!("From:        {}", msg.mail_from);
70                println!("Subject:     {}", msg.mail_subject);
71                println!(
72                    "Excerpt:     {}",
73                    &msg.mail_excerpt[..msg.mail_excerpt.len().min(80)]
74                );
75                println!("Timestamp:   {}", msg.mail_timestamp);
76
77                // =========================================
78                // 4. Fetch full email content (fetch_email)
79                // =========================================
80                println!("\n📄 Fetching full email body...");
81                match client.fetch_email(&email, &msg.mail_id).await {
82                    Ok(details) => {
83                        println!("   Body length: {} characters", details.mail_body.len());
84                        println!("   Preview (first 500 chars):");
85                        println!("   {}", "-".repeat(40));
86                        let preview: String = details.mail_body.chars().take(500).collect();
87                        for line in preview.lines().take(10) {
88                            println!("   {}", line);
89                        }
90                        if details.mail_body.len() > 500 {
91                            println!("   ... (truncated)");
92                        }
93                    }
94                    Err(e) => {
95                        eprintln!("   ❌ Failed to fetch: {}", e);
96                    }
97                }
98            }
99            break;
100        }
101
102        if start.elapsed() >= timeout {
103            println!("\n\n⚠️  Timeout: No messages received");
104            break;
105        }
106
107        let remaining = (timeout - start.elapsed()).as_secs();
108        print!("\r   Checking... {} seconds remaining   ", remaining);
109        use std::io::Write;
110        std::io::stdout().flush().ok();
111
112        tokio::time::sleep(poll_interval).await;
113    }
114
115    // =========================================
116    // 5. Delete/forget email address
117    // =========================================
118    println!("\n🗑️  Cleaning up email address...");
119    match client.delete_email(&email).await {
120        Ok(true) => println!("   ✅ Email address deleted"),
121        Ok(false) => println!("   ⚠️  Deletion may have failed"),
122        Err(e) => eprintln!("   ❌ Error: {}", e),
123    }
124
125    println!("\n{}", "=".repeat(50));
126    println!("✨ Demo complete!");
127
128    Ok(())
129}
Source

pub async fn get_messages(&self, email: &str) -> Result<Vec<Message>>

Get messages for an email address.

§Arguments
  • email - The full email address
§Returns

A list of messages in the inbox

Examples found in repository?
examples/demo.rs (line 61)
14async fn main() -> Result<(), Box<dyn std::error::Error>> {
15    println!("📧 GuerrillaMail Rust Client - Full Demo");
16    println!("{}", "=".repeat(50));
17
18    // =========================================
19    // 1. Create client (optionally with proxy)
20    // =========================================
21    println!("\n🔌 Creating client...");
22
23    // Without proxy:
24    let client = Client::new().await?;
25
26    // With proxy (uncomment to use):
27    // let client = Client::builder().proxy("http://127.0.0.1:8080").build().await?;
28
29    // Custom configuration example (uncomment to use):
30    // let client = Client::builder()
31    //     .proxy("http://127.0.0.1:8080")
32    //     .danger_accept_invalid_certs(false)
33    //     .user_agent("guerrillamail-demo/1.0")
34    //     .ajax_url("https://www.guerrillamail.com/ajax.php")
35    //     .build()
36    //     .await?;
37
38    println!("   ✅ Connected to GuerrillaMail API");
39
40    // =========================================
41    // 2. Create temporary email address
42    // =========================================
43    println!("\n📬 Creating temporary email...");
44    let alias = format!("demo{}", rand::random::<u16>());
45    let email = client.create_email(&alias).await?;
46    println!("   ✅ Created: {}", email);
47
48    // =========================================
49    // 3. Poll for messages (get_messages)
50    // =========================================
51    println!("\n⏳ Waiting for messages...");
52    println!("   Send an email to: {}", email);
53    println!("   (Polling for up to 2 minutes)");
54
55    let start = std::time::Instant::now();
56    let timeout = std::time::Duration::from_secs(120);
57    let poll_interval = std::time::Duration::from_secs(5);
58
59    loop {
60        // get_messages returns basic info: id, from, subject, excerpt
61        let messages = client.get_messages(&email).await?;
62
63        if !messages.is_empty() {
64            println!("\n\n📥 Received {} message(s)!", messages.len());
65
66            for msg in &messages {
67                println!("\n{}", "-".repeat(50));
68                println!("Message ID:  {}", msg.mail_id);
69                println!("From:        {}", msg.mail_from);
70                println!("Subject:     {}", msg.mail_subject);
71                println!(
72                    "Excerpt:     {}",
73                    &msg.mail_excerpt[..msg.mail_excerpt.len().min(80)]
74                );
75                println!("Timestamp:   {}", msg.mail_timestamp);
76
77                // =========================================
78                // 4. Fetch full email content (fetch_email)
79                // =========================================
80                println!("\n📄 Fetching full email body...");
81                match client.fetch_email(&email, &msg.mail_id).await {
82                    Ok(details) => {
83                        println!("   Body length: {} characters", details.mail_body.len());
84                        println!("   Preview (first 500 chars):");
85                        println!("   {}", "-".repeat(40));
86                        let preview: String = details.mail_body.chars().take(500).collect();
87                        for line in preview.lines().take(10) {
88                            println!("   {}", line);
89                        }
90                        if details.mail_body.len() > 500 {
91                            println!("   ... (truncated)");
92                        }
93                    }
94                    Err(e) => {
95                        eprintln!("   ❌ Failed to fetch: {}", e);
96                    }
97                }
98            }
99            break;
100        }
101
102        if start.elapsed() >= timeout {
103            println!("\n\n⚠️  Timeout: No messages received");
104            break;
105        }
106
107        let remaining = (timeout - start.elapsed()).as_secs();
108        print!("\r   Checking... {} seconds remaining   ", remaining);
109        use std::io::Write;
110        std::io::stdout().flush().ok();
111
112        tokio::time::sleep(poll_interval).await;
113    }
114
115    // =========================================
116    // 5. Delete/forget email address
117    // =========================================
118    println!("\n🗑️  Cleaning up email address...");
119    match client.delete_email(&email).await {
120        Ok(true) => println!("   ✅ Email address deleted"),
121        Ok(false) => println!("   ⚠️  Deletion may have failed"),
122        Err(e) => eprintln!("   ❌ Error: {}", e),
123    }
124
125    println!("\n{}", "=".repeat(50));
126    println!("✨ Demo complete!");
127
128    Ok(())
129}
Source

pub async fn fetch_email( &self, email: &str, mail_id: &str, ) -> Result<EmailDetails>

Fetch the full content of a specific email.

§Arguments
  • email - The full email address
  • mail_id - The message ID to fetch
§Returns

The full email details including the body

Examples found in repository?
examples/demo.rs (line 81)
14async fn main() -> Result<(), Box<dyn std::error::Error>> {
15    println!("📧 GuerrillaMail Rust Client - Full Demo");
16    println!("{}", "=".repeat(50));
17
18    // =========================================
19    // 1. Create client (optionally with proxy)
20    // =========================================
21    println!("\n🔌 Creating client...");
22
23    // Without proxy:
24    let client = Client::new().await?;
25
26    // With proxy (uncomment to use):
27    // let client = Client::builder().proxy("http://127.0.0.1:8080").build().await?;
28
29    // Custom configuration example (uncomment to use):
30    // let client = Client::builder()
31    //     .proxy("http://127.0.0.1:8080")
32    //     .danger_accept_invalid_certs(false)
33    //     .user_agent("guerrillamail-demo/1.0")
34    //     .ajax_url("https://www.guerrillamail.com/ajax.php")
35    //     .build()
36    //     .await?;
37
38    println!("   ✅ Connected to GuerrillaMail API");
39
40    // =========================================
41    // 2. Create temporary email address
42    // =========================================
43    println!("\n📬 Creating temporary email...");
44    let alias = format!("demo{}", rand::random::<u16>());
45    let email = client.create_email(&alias).await?;
46    println!("   ✅ Created: {}", email);
47
48    // =========================================
49    // 3. Poll for messages (get_messages)
50    // =========================================
51    println!("\n⏳ Waiting for messages...");
52    println!("   Send an email to: {}", email);
53    println!("   (Polling for up to 2 minutes)");
54
55    let start = std::time::Instant::now();
56    let timeout = std::time::Duration::from_secs(120);
57    let poll_interval = std::time::Duration::from_secs(5);
58
59    loop {
60        // get_messages returns basic info: id, from, subject, excerpt
61        let messages = client.get_messages(&email).await?;
62
63        if !messages.is_empty() {
64            println!("\n\n📥 Received {} message(s)!", messages.len());
65
66            for msg in &messages {
67                println!("\n{}", "-".repeat(50));
68                println!("Message ID:  {}", msg.mail_id);
69                println!("From:        {}", msg.mail_from);
70                println!("Subject:     {}", msg.mail_subject);
71                println!(
72                    "Excerpt:     {}",
73                    &msg.mail_excerpt[..msg.mail_excerpt.len().min(80)]
74                );
75                println!("Timestamp:   {}", msg.mail_timestamp);
76
77                // =========================================
78                // 4. Fetch full email content (fetch_email)
79                // =========================================
80                println!("\n📄 Fetching full email body...");
81                match client.fetch_email(&email, &msg.mail_id).await {
82                    Ok(details) => {
83                        println!("   Body length: {} characters", details.mail_body.len());
84                        println!("   Preview (first 500 chars):");
85                        println!("   {}", "-".repeat(40));
86                        let preview: String = details.mail_body.chars().take(500).collect();
87                        for line in preview.lines().take(10) {
88                            println!("   {}", line);
89                        }
90                        if details.mail_body.len() > 500 {
91                            println!("   ... (truncated)");
92                        }
93                    }
94                    Err(e) => {
95                        eprintln!("   ❌ Failed to fetch: {}", e);
96                    }
97                }
98            }
99            break;
100        }
101
102        if start.elapsed() >= timeout {
103            println!("\n\n⚠️  Timeout: No messages received");
104            break;
105        }
106
107        let remaining = (timeout - start.elapsed()).as_secs();
108        print!("\r   Checking... {} seconds remaining   ", remaining);
109        use std::io::Write;
110        std::io::stdout().flush().ok();
111
112        tokio::time::sleep(poll_interval).await;
113    }
114
115    // =========================================
116    // 5. Delete/forget email address
117    // =========================================
118    println!("\n🗑️  Cleaning up email address...");
119    match client.delete_email(&email).await {
120        Ok(true) => println!("   ✅ Email address deleted"),
121        Ok(false) => println!("   ⚠️  Deletion may have failed"),
122        Err(e) => eprintln!("   ❌ Error: {}", e),
123    }
124
125    println!("\n{}", "=".repeat(50));
126    println!("✨ Demo complete!");
127
128    Ok(())
129}
Source

pub async fn delete_email(&self, email: &str) -> Result<bool>

Delete/forget an email address.

§Arguments
  • email - The full email address to delete
§Returns

true if deletion was successful

Examples found in repository?
examples/demo.rs (line 119)
14async fn main() -> Result<(), Box<dyn std::error::Error>> {
15    println!("📧 GuerrillaMail Rust Client - Full Demo");
16    println!("{}", "=".repeat(50));
17
18    // =========================================
19    // 1. Create client (optionally with proxy)
20    // =========================================
21    println!("\n🔌 Creating client...");
22
23    // Without proxy:
24    let client = Client::new().await?;
25
26    // With proxy (uncomment to use):
27    // let client = Client::builder().proxy("http://127.0.0.1:8080").build().await?;
28
29    // Custom configuration example (uncomment to use):
30    // let client = Client::builder()
31    //     .proxy("http://127.0.0.1:8080")
32    //     .danger_accept_invalid_certs(false)
33    //     .user_agent("guerrillamail-demo/1.0")
34    //     .ajax_url("https://www.guerrillamail.com/ajax.php")
35    //     .build()
36    //     .await?;
37
38    println!("   ✅ Connected to GuerrillaMail API");
39
40    // =========================================
41    // 2. Create temporary email address
42    // =========================================
43    println!("\n📬 Creating temporary email...");
44    let alias = format!("demo{}", rand::random::<u16>());
45    let email = client.create_email(&alias).await?;
46    println!("   ✅ Created: {}", email);
47
48    // =========================================
49    // 3. Poll for messages (get_messages)
50    // =========================================
51    println!("\n⏳ Waiting for messages...");
52    println!("   Send an email to: {}", email);
53    println!("   (Polling for up to 2 minutes)");
54
55    let start = std::time::Instant::now();
56    let timeout = std::time::Duration::from_secs(120);
57    let poll_interval = std::time::Duration::from_secs(5);
58
59    loop {
60        // get_messages returns basic info: id, from, subject, excerpt
61        let messages = client.get_messages(&email).await?;
62
63        if !messages.is_empty() {
64            println!("\n\n📥 Received {} message(s)!", messages.len());
65
66            for msg in &messages {
67                println!("\n{}", "-".repeat(50));
68                println!("Message ID:  {}", msg.mail_id);
69                println!("From:        {}", msg.mail_from);
70                println!("Subject:     {}", msg.mail_subject);
71                println!(
72                    "Excerpt:     {}",
73                    &msg.mail_excerpt[..msg.mail_excerpt.len().min(80)]
74                );
75                println!("Timestamp:   {}", msg.mail_timestamp);
76
77                // =========================================
78                // 4. Fetch full email content (fetch_email)
79                // =========================================
80                println!("\n📄 Fetching full email body...");
81                match client.fetch_email(&email, &msg.mail_id).await {
82                    Ok(details) => {
83                        println!("   Body length: {} characters", details.mail_body.len());
84                        println!("   Preview (first 500 chars):");
85                        println!("   {}", "-".repeat(40));
86                        let preview: String = details.mail_body.chars().take(500).collect();
87                        for line in preview.lines().take(10) {
88                            println!("   {}", line);
89                        }
90                        if details.mail_body.len() > 500 {
91                            println!("   ... (truncated)");
92                        }
93                    }
94                    Err(e) => {
95                        eprintln!("   ❌ Failed to fetch: {}", e);
96                    }
97                }
98            }
99            break;
100        }
101
102        if start.elapsed() >= timeout {
103            println!("\n\n⚠️  Timeout: No messages received");
104            break;
105        }
106
107        let remaining = (timeout - start.elapsed()).as_secs();
108        print!("\r   Checking... {} seconds remaining   ", remaining);
109        use std::io::Write;
110        std::io::stdout().flush().ok();
111
112        tokio::time::sleep(poll_interval).await;
113    }
114
115    // =========================================
116    // 5. Delete/forget email address
117    // =========================================
118    println!("\n🗑️  Cleaning up email address...");
119    match client.delete_email(&email).await {
120        Ok(true) => println!("   ✅ Email address deleted"),
121        Ok(false) => println!("   ⚠️  Deletion may have failed"),
122        Err(e) => eprintln!("   ❌ Error: {}", e),
123    }
124
125    println!("\n{}", "=".repeat(50));
126    println!("✨ Demo complete!");
127
128    Ok(())
129}

Trait Implementations§

Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more