pub struct Client { /* private fields */ }Expand description
Async client for GuerrillaMail temporary email service.
Implementations§
Source§impl Client
impl Client
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Create a builder for configuring the client.
Sourcepub async fn new() -> Result<Self>
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. View available domains
42 // =========================================
43 println!("\n🌐 Available email domains:");
44 for domain in client.domains() {
45 println!(" - {}", domain);
46 }
47
48 // =========================================
49 // 3. Create temporary email address
50 // =========================================
51 println!("\n📬 Creating temporary email...");
52 let alias = format!("demo{}", rand::random::<u16>());
53 let email = client.create_email(&alias).await?;
54 println!(" ✅ Created: {}", email);
55
56 // =========================================
57 // 4. Poll for messages (get_messages)
58 // =========================================
59 println!("\n⏳ Waiting for messages...");
60 println!(" Send an email to: {}", email);
61 println!(" (Polling for up to 2 minutes)");
62
63 let start = std::time::Instant::now();
64 let timeout = std::time::Duration::from_secs(120);
65 let poll_interval = std::time::Duration::from_secs(5);
66
67 loop {
68 // get_messages returns basic info: id, from, subject, excerpt
69 let messages = client.get_messages(&email).await?;
70
71 if !messages.is_empty() {
72 println!("\n\n📥 Received {} message(s)!", messages.len());
73
74 for msg in &messages {
75 println!("\n{}", "-".repeat(50));
76 println!("Message ID: {}", msg.mail_id);
77 println!("From: {}", msg.mail_from);
78 println!("Subject: {}", msg.mail_subject);
79 println!(
80 "Excerpt: {}",
81 &msg.mail_excerpt[..msg.mail_excerpt.len().min(80)]
82 );
83 println!("Timestamp: {}", msg.mail_timestamp);
84
85 // =========================================
86 // 5. Fetch full email content (fetch_email)
87 // =========================================
88 println!("\n📄 Fetching full email body...");
89 match client.fetch_email(&email, &msg.mail_id).await {
90 Ok(details) => {
91 println!(" Body length: {} characters", details.mail_body.len());
92 println!(" Preview (first 500 chars):");
93 println!(" {}", "-".repeat(40));
94 let preview: String = details.mail_body.chars().take(500).collect();
95 for line in preview.lines().take(10) {
96 println!(" {}", line);
97 }
98 if details.mail_body.len() > 500 {
99 println!(" ... (truncated)");
100 }
101 }
102 Err(e) => {
103 eprintln!(" ❌ Failed to fetch: {}", e);
104 }
105 }
106 }
107 break;
108 }
109
110 if start.elapsed() >= timeout {
111 println!("\n\n⚠️ Timeout: No messages received");
112 break;
113 }
114
115 let remaining = (timeout - start.elapsed()).as_secs();
116 print!("\r Checking... {} seconds remaining ", remaining);
117 use std::io::Write;
118 std::io::stdout().flush().ok();
119
120 tokio::time::sleep(poll_interval).await;
121 }
122
123 // =========================================
124 // 6. Delete/forget email address
125 // =========================================
126 println!("\n🗑️ Cleaning up email address...");
127 match client.delete_email(&email).await {
128 Ok(true) => println!(" ✅ Email address deleted"),
129 Ok(false) => println!(" ⚠️ Deletion may have failed"),
130 Err(e) => eprintln!(" ❌ Error: {}", e),
131 }
132
133 println!("\n{}", "=".repeat(50));
134 println!("✨ Demo complete!");
135
136 Ok(())
137}Sourcepub async fn with_proxy(proxy: Option<&str>) -> Result<Self>
pub async fn with_proxy(proxy: Option<&str>) -> Result<Self>
Create a new GuerrillaMail client with an optional proxy.
§Arguments
proxy- Optional proxy URL (e.g., “http://127.0.0.1:8080”)
Sourcepub fn domains(&self) -> &[String]
pub fn domains(&self) -> &[String]
Get the list of available email domains.
Examples found in repository?
examples/demo.rs (line 44)
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. View available domains
42 // =========================================
43 println!("\n🌐 Available email domains:");
44 for domain in client.domains() {
45 println!(" - {}", domain);
46 }
47
48 // =========================================
49 // 3. Create temporary email address
50 // =========================================
51 println!("\n📬 Creating temporary email...");
52 let alias = format!("demo{}", rand::random::<u16>());
53 let email = client.create_email(&alias).await?;
54 println!(" ✅ Created: {}", email);
55
56 // =========================================
57 // 4. Poll for messages (get_messages)
58 // =========================================
59 println!("\n⏳ Waiting for messages...");
60 println!(" Send an email to: {}", email);
61 println!(" (Polling for up to 2 minutes)");
62
63 let start = std::time::Instant::now();
64 let timeout = std::time::Duration::from_secs(120);
65 let poll_interval = std::time::Duration::from_secs(5);
66
67 loop {
68 // get_messages returns basic info: id, from, subject, excerpt
69 let messages = client.get_messages(&email).await?;
70
71 if !messages.is_empty() {
72 println!("\n\n📥 Received {} message(s)!", messages.len());
73
74 for msg in &messages {
75 println!("\n{}", "-".repeat(50));
76 println!("Message ID: {}", msg.mail_id);
77 println!("From: {}", msg.mail_from);
78 println!("Subject: {}", msg.mail_subject);
79 println!(
80 "Excerpt: {}",
81 &msg.mail_excerpt[..msg.mail_excerpt.len().min(80)]
82 );
83 println!("Timestamp: {}", msg.mail_timestamp);
84
85 // =========================================
86 // 5. Fetch full email content (fetch_email)
87 // =========================================
88 println!("\n📄 Fetching full email body...");
89 match client.fetch_email(&email, &msg.mail_id).await {
90 Ok(details) => {
91 println!(" Body length: {} characters", details.mail_body.len());
92 println!(" Preview (first 500 chars):");
93 println!(" {}", "-".repeat(40));
94 let preview: String = details.mail_body.chars().take(500).collect();
95 for line in preview.lines().take(10) {
96 println!(" {}", line);
97 }
98 if details.mail_body.len() > 500 {
99 println!(" ... (truncated)");
100 }
101 }
102 Err(e) => {
103 eprintln!(" ❌ Failed to fetch: {}", e);
104 }
105 }
106 }
107 break;
108 }
109
110 if start.elapsed() >= timeout {
111 println!("\n\n⚠️ Timeout: No messages received");
112 break;
113 }
114
115 let remaining = (timeout - start.elapsed()).as_secs();
116 print!("\r Checking... {} seconds remaining ", remaining);
117 use std::io::Write;
118 std::io::stdout().flush().ok();
119
120 tokio::time::sleep(poll_interval).await;
121 }
122
123 // =========================================
124 // 6. Delete/forget email address
125 // =========================================
126 println!("\n🗑️ Cleaning up email address...");
127 match client.delete_email(&email).await {
128 Ok(true) => println!(" ✅ Email address deleted"),
129 Ok(false) => println!(" ⚠️ Deletion may have failed"),
130 Err(e) => eprintln!(" ❌ Error: {}", e),
131 }
132
133 println!("\n{}", "=".repeat(50));
134 println!("✨ Demo complete!");
135
136 Ok(())
137}Sourcepub async fn create_email(&self, alias: &str) -> Result<String>
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 53)
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. View available domains
42 // =========================================
43 println!("\n🌐 Available email domains:");
44 for domain in client.domains() {
45 println!(" - {}", domain);
46 }
47
48 // =========================================
49 // 3. Create temporary email address
50 // =========================================
51 println!("\n📬 Creating temporary email...");
52 let alias = format!("demo{}", rand::random::<u16>());
53 let email = client.create_email(&alias).await?;
54 println!(" ✅ Created: {}", email);
55
56 // =========================================
57 // 4. Poll for messages (get_messages)
58 // =========================================
59 println!("\n⏳ Waiting for messages...");
60 println!(" Send an email to: {}", email);
61 println!(" (Polling for up to 2 minutes)");
62
63 let start = std::time::Instant::now();
64 let timeout = std::time::Duration::from_secs(120);
65 let poll_interval = std::time::Duration::from_secs(5);
66
67 loop {
68 // get_messages returns basic info: id, from, subject, excerpt
69 let messages = client.get_messages(&email).await?;
70
71 if !messages.is_empty() {
72 println!("\n\n📥 Received {} message(s)!", messages.len());
73
74 for msg in &messages {
75 println!("\n{}", "-".repeat(50));
76 println!("Message ID: {}", msg.mail_id);
77 println!("From: {}", msg.mail_from);
78 println!("Subject: {}", msg.mail_subject);
79 println!(
80 "Excerpt: {}",
81 &msg.mail_excerpt[..msg.mail_excerpt.len().min(80)]
82 );
83 println!("Timestamp: {}", msg.mail_timestamp);
84
85 // =========================================
86 // 5. Fetch full email content (fetch_email)
87 // =========================================
88 println!("\n📄 Fetching full email body...");
89 match client.fetch_email(&email, &msg.mail_id).await {
90 Ok(details) => {
91 println!(" Body length: {} characters", details.mail_body.len());
92 println!(" Preview (first 500 chars):");
93 println!(" {}", "-".repeat(40));
94 let preview: String = details.mail_body.chars().take(500).collect();
95 for line in preview.lines().take(10) {
96 println!(" {}", line);
97 }
98 if details.mail_body.len() > 500 {
99 println!(" ... (truncated)");
100 }
101 }
102 Err(e) => {
103 eprintln!(" ❌ Failed to fetch: {}", e);
104 }
105 }
106 }
107 break;
108 }
109
110 if start.elapsed() >= timeout {
111 println!("\n\n⚠️ Timeout: No messages received");
112 break;
113 }
114
115 let remaining = (timeout - start.elapsed()).as_secs();
116 print!("\r Checking... {} seconds remaining ", remaining);
117 use std::io::Write;
118 std::io::stdout().flush().ok();
119
120 tokio::time::sleep(poll_interval).await;
121 }
122
123 // =========================================
124 // 6. Delete/forget email address
125 // =========================================
126 println!("\n🗑️ Cleaning up email address...");
127 match client.delete_email(&email).await {
128 Ok(true) => println!(" ✅ Email address deleted"),
129 Ok(false) => println!(" ⚠️ Deletion may have failed"),
130 Err(e) => eprintln!(" ❌ Error: {}", e),
131 }
132
133 println!("\n{}", "=".repeat(50));
134 println!("✨ Demo complete!");
135
136 Ok(())
137}Sourcepub async fn get_messages(&self, email: &str) -> Result<Vec<Message>>
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 69)
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. View available domains
42 // =========================================
43 println!("\n🌐 Available email domains:");
44 for domain in client.domains() {
45 println!(" - {}", domain);
46 }
47
48 // =========================================
49 // 3. Create temporary email address
50 // =========================================
51 println!("\n📬 Creating temporary email...");
52 let alias = format!("demo{}", rand::random::<u16>());
53 let email = client.create_email(&alias).await?;
54 println!(" ✅ Created: {}", email);
55
56 // =========================================
57 // 4. Poll for messages (get_messages)
58 // =========================================
59 println!("\n⏳ Waiting for messages...");
60 println!(" Send an email to: {}", email);
61 println!(" (Polling for up to 2 minutes)");
62
63 let start = std::time::Instant::now();
64 let timeout = std::time::Duration::from_secs(120);
65 let poll_interval = std::time::Duration::from_secs(5);
66
67 loop {
68 // get_messages returns basic info: id, from, subject, excerpt
69 let messages = client.get_messages(&email).await?;
70
71 if !messages.is_empty() {
72 println!("\n\n📥 Received {} message(s)!", messages.len());
73
74 for msg in &messages {
75 println!("\n{}", "-".repeat(50));
76 println!("Message ID: {}", msg.mail_id);
77 println!("From: {}", msg.mail_from);
78 println!("Subject: {}", msg.mail_subject);
79 println!(
80 "Excerpt: {}",
81 &msg.mail_excerpt[..msg.mail_excerpt.len().min(80)]
82 );
83 println!("Timestamp: {}", msg.mail_timestamp);
84
85 // =========================================
86 // 5. Fetch full email content (fetch_email)
87 // =========================================
88 println!("\n📄 Fetching full email body...");
89 match client.fetch_email(&email, &msg.mail_id).await {
90 Ok(details) => {
91 println!(" Body length: {} characters", details.mail_body.len());
92 println!(" Preview (first 500 chars):");
93 println!(" {}", "-".repeat(40));
94 let preview: String = details.mail_body.chars().take(500).collect();
95 for line in preview.lines().take(10) {
96 println!(" {}", line);
97 }
98 if details.mail_body.len() > 500 {
99 println!(" ... (truncated)");
100 }
101 }
102 Err(e) => {
103 eprintln!(" ❌ Failed to fetch: {}", e);
104 }
105 }
106 }
107 break;
108 }
109
110 if start.elapsed() >= timeout {
111 println!("\n\n⚠️ Timeout: No messages received");
112 break;
113 }
114
115 let remaining = (timeout - start.elapsed()).as_secs();
116 print!("\r Checking... {} seconds remaining ", remaining);
117 use std::io::Write;
118 std::io::stdout().flush().ok();
119
120 tokio::time::sleep(poll_interval).await;
121 }
122
123 // =========================================
124 // 6. Delete/forget email address
125 // =========================================
126 println!("\n🗑️ Cleaning up email address...");
127 match client.delete_email(&email).await {
128 Ok(true) => println!(" ✅ Email address deleted"),
129 Ok(false) => println!(" ⚠️ Deletion may have failed"),
130 Err(e) => eprintln!(" ❌ Error: {}", e),
131 }
132
133 println!("\n{}", "=".repeat(50));
134 println!("✨ Demo complete!");
135
136 Ok(())
137}Sourcepub async fn fetch_email(
&self,
email: &str,
mail_id: &str,
) -> Result<EmailDetails>
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 addressmail_id- The message ID to fetch
§Returns
The full email details including the body
Examples found in repository?
examples/demo.rs (line 89)
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. View available domains
42 // =========================================
43 println!("\n🌐 Available email domains:");
44 for domain in client.domains() {
45 println!(" - {}", domain);
46 }
47
48 // =========================================
49 // 3. Create temporary email address
50 // =========================================
51 println!("\n📬 Creating temporary email...");
52 let alias = format!("demo{}", rand::random::<u16>());
53 let email = client.create_email(&alias).await?;
54 println!(" ✅ Created: {}", email);
55
56 // =========================================
57 // 4. Poll for messages (get_messages)
58 // =========================================
59 println!("\n⏳ Waiting for messages...");
60 println!(" Send an email to: {}", email);
61 println!(" (Polling for up to 2 minutes)");
62
63 let start = std::time::Instant::now();
64 let timeout = std::time::Duration::from_secs(120);
65 let poll_interval = std::time::Duration::from_secs(5);
66
67 loop {
68 // get_messages returns basic info: id, from, subject, excerpt
69 let messages = client.get_messages(&email).await?;
70
71 if !messages.is_empty() {
72 println!("\n\n📥 Received {} message(s)!", messages.len());
73
74 for msg in &messages {
75 println!("\n{}", "-".repeat(50));
76 println!("Message ID: {}", msg.mail_id);
77 println!("From: {}", msg.mail_from);
78 println!("Subject: {}", msg.mail_subject);
79 println!(
80 "Excerpt: {}",
81 &msg.mail_excerpt[..msg.mail_excerpt.len().min(80)]
82 );
83 println!("Timestamp: {}", msg.mail_timestamp);
84
85 // =========================================
86 // 5. Fetch full email content (fetch_email)
87 // =========================================
88 println!("\n📄 Fetching full email body...");
89 match client.fetch_email(&email, &msg.mail_id).await {
90 Ok(details) => {
91 println!(" Body length: {} characters", details.mail_body.len());
92 println!(" Preview (first 500 chars):");
93 println!(" {}", "-".repeat(40));
94 let preview: String = details.mail_body.chars().take(500).collect();
95 for line in preview.lines().take(10) {
96 println!(" {}", line);
97 }
98 if details.mail_body.len() > 500 {
99 println!(" ... (truncated)");
100 }
101 }
102 Err(e) => {
103 eprintln!(" ❌ Failed to fetch: {}", e);
104 }
105 }
106 }
107 break;
108 }
109
110 if start.elapsed() >= timeout {
111 println!("\n\n⚠️ Timeout: No messages received");
112 break;
113 }
114
115 let remaining = (timeout - start.elapsed()).as_secs();
116 print!("\r Checking... {} seconds remaining ", remaining);
117 use std::io::Write;
118 std::io::stdout().flush().ok();
119
120 tokio::time::sleep(poll_interval).await;
121 }
122
123 // =========================================
124 // 6. Delete/forget email address
125 // =========================================
126 println!("\n🗑️ Cleaning up email address...");
127 match client.delete_email(&email).await {
128 Ok(true) => println!(" ✅ Email address deleted"),
129 Ok(false) => println!(" ⚠️ Deletion may have failed"),
130 Err(e) => eprintln!(" ❌ Error: {}", e),
131 }
132
133 println!("\n{}", "=".repeat(50));
134 println!("✨ Demo complete!");
135
136 Ok(())
137}Sourcepub async fn delete_email(&self, email: &str) -> Result<bool>
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 127)
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. View available domains
42 // =========================================
43 println!("\n🌐 Available email domains:");
44 for domain in client.domains() {
45 println!(" - {}", domain);
46 }
47
48 // =========================================
49 // 3. Create temporary email address
50 // =========================================
51 println!("\n📬 Creating temporary email...");
52 let alias = format!("demo{}", rand::random::<u16>());
53 let email = client.create_email(&alias).await?;
54 println!(" ✅ Created: {}", email);
55
56 // =========================================
57 // 4. Poll for messages (get_messages)
58 // =========================================
59 println!("\n⏳ Waiting for messages...");
60 println!(" Send an email to: {}", email);
61 println!(" (Polling for up to 2 minutes)");
62
63 let start = std::time::Instant::now();
64 let timeout = std::time::Duration::from_secs(120);
65 let poll_interval = std::time::Duration::from_secs(5);
66
67 loop {
68 // get_messages returns basic info: id, from, subject, excerpt
69 let messages = client.get_messages(&email).await?;
70
71 if !messages.is_empty() {
72 println!("\n\n📥 Received {} message(s)!", messages.len());
73
74 for msg in &messages {
75 println!("\n{}", "-".repeat(50));
76 println!("Message ID: {}", msg.mail_id);
77 println!("From: {}", msg.mail_from);
78 println!("Subject: {}", msg.mail_subject);
79 println!(
80 "Excerpt: {}",
81 &msg.mail_excerpt[..msg.mail_excerpt.len().min(80)]
82 );
83 println!("Timestamp: {}", msg.mail_timestamp);
84
85 // =========================================
86 // 5. Fetch full email content (fetch_email)
87 // =========================================
88 println!("\n📄 Fetching full email body...");
89 match client.fetch_email(&email, &msg.mail_id).await {
90 Ok(details) => {
91 println!(" Body length: {} characters", details.mail_body.len());
92 println!(" Preview (first 500 chars):");
93 println!(" {}", "-".repeat(40));
94 let preview: String = details.mail_body.chars().take(500).collect();
95 for line in preview.lines().take(10) {
96 println!(" {}", line);
97 }
98 if details.mail_body.len() > 500 {
99 println!(" ... (truncated)");
100 }
101 }
102 Err(e) => {
103 eprintln!(" ❌ Failed to fetch: {}", e);
104 }
105 }
106 }
107 break;
108 }
109
110 if start.elapsed() >= timeout {
111 println!("\n\n⚠️ Timeout: No messages received");
112 break;
113 }
114
115 let remaining = (timeout - start.elapsed()).as_secs();
116 print!("\r Checking... {} seconds remaining ", remaining);
117 use std::io::Write;
118 std::io::stdout().flush().ok();
119
120 tokio::time::sleep(poll_interval).await;
121 }
122
123 // =========================================
124 // 6. Delete/forget email address
125 // =========================================
126 println!("\n🗑️ Cleaning up email address...");
127 match client.delete_email(&email).await {
128 Ok(true) => println!(" ✅ Email address deleted"),
129 Ok(false) => println!(" ⚠️ Deletion may have failed"),
130 Err(e) => eprintln!(" ❌ Error: {}", e),
131 }
132
133 println!("\n{}", "=".repeat(50));
134 println!("✨ Demo complete!");
135
136 Ok(())
137}Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more