-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample_mail_tm.py
More file actions
40 lines (28 loc) · 1023 Bytes
/
Copy pathexample_mail_tm.py
File metadata and controls
40 lines (28 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Example: Using mail.tm provider."""
from tempmail_wrapper import MailTmProvider
def main() -> None:
provider = MailTmProvider()
# Generate email (auto-registers account and gets Bearer token)
email = provider.generate_email()
print(f"Generated email: {email}")
# Check inbox
inbox = provider.get_inbox(email)
print(f"Inbox has {len(inbox)} messages")
# Wait for an email
print("Waiting for email... (send one now!)")
msg = provider.wait_for_email(email, timeout=120, interval=10)
if msg:
print(f"\nReceived from: {msg.sender}")
print(f"Subject: {msg.subject}")
# Read full message
detail = provider.read_message(msg.id)
print(f"\nBody:\n{detail.body_text}")
if detail.attachments:
print(f"\nAttachments: {len(detail.attachments)}")
else:
print("Timeout — no email received.")
# Cleanup
provider.delete_email(email)
print("Session closed.")
if __name__ == "__main__":
main()