Repository navigation
Expand file tree
/
Copy pathexample.py
More file actions
64 lines (52 loc) · 2.11 KB
/
Copy pathexample.py
File metadata and controls
64 lines (52 loc) · 2.11 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
Example usage of the EmailRoutingApp with OOP approach.
"""
import asyncio
from models.email_models import EmailConfig
from managers.email_manager import EmailRuleManager
async def example_usage():
"""Demonstrate the OOP usage of the email routing system."""
# Configuration - replace with your actual values
config = EmailConfig(
api_token="your_api_token_here",
zone_id="your_zone_id_here",
domain="yourdomain.com"
)
# Create the manager
manager = EmailRuleManager(config)
print("Email Routing Manager Example")
print("=" * 40)
try:
# Example 1: Create 5 email rules
print("\n1. Creating 5 email rules...")
results = await manager.create_email_rules(
destination_email="your-destination@email.com",
count=5,
email_length=8,
delay=1.0
)
print(f"Created {len([r for r in results if r.success])} rules successfully")
# Example 2: List all rules
print("\n2. Listing all rules...")
rules = await manager.list_rules()
print(f"Found {len(rules)} total rules")
# Example 3: Update destinations (with filter)
print("\n3. Updating destinations for rules containing 'test'...")
update_results = await manager.update_destinations(
new_destination="new-destination@email.com",
filter_text="test", # Only update rules with 'test' in name
delay=1.0
)
print(f"Updated {len([r for r in update_results if r.success])} rules")
# Example 4: Delete rules (with filter)
print("\n4. Deleting rules containing 'temp'...")
delete_results = await manager.delete_rules(
filter_text="temp", # Only delete rules with 'temp' in name
delay=1.0
)
print(f"Deleted {len([r for r in delete_results if r.success])} rules")
except Exception as e:
print(f"Error: {e}")
print("Make sure to configure your API credentials in config.py")
if __name__ == "__main__":
asyncio.run(example_usage())