-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_emails.py
More file actions
122 lines (107 loc) · 3.96 KB
/
test_emails.py
File metadata and controls
122 lines (107 loc) · 3.96 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
import subprocess
import time
from typing import Dict, Tuple
# Test email configurations for different agent types
TEST_EMAILS = [
{
"from": "david.gilardi+deal@datastax.com",
"to": "deals@dev.email-agent.ai",
"subject": "Test Email from Terminal",
"body": "what are the latest deals on the nintendo switch?"
},
{
"from": "david.gilardi+travel@datastax.com",
"to": "travel@dev.email-agent.ai",
"subject": "Test Email from Terminal",
"body": (
"Let's plan a fun cocktail dinner in Orlando, FL for tonight at 8PM. "
"Just pick a place for me. Include a map link to the location."
)
},
{
"from": "david.gilardi+financial@datastax.com",
"to": "financial@dev.email-agent.ai",
"subject": "Test Email from Terminal",
"body": "What is the current financial situation for Nvidia today?"
},
{
"from": "david.gilardi+research@datastax.com",
"to": "research@dev.email-agent.ai",
"subject": "Test Email from Terminal",
"body": (
"Research the effectiveness of different prompt engineering techniques in controlling "
"AI hallucinations, with focus on real-world applications and empirical studies."
)
}
]
def send_test_email(email_config: Dict[str, str]) -> Tuple[bool, str]:
"""
Send a test email using sendmail.
Args:
email_config (Dict[str, str]): Email configuration with from, to, subject, and body
Returns:
Tuple[bool, str]: (Success status, Error message if any)
"""
try:
# Format the email content
email_content = (
f"From: {email_config['from']}\n"
f"To: {email_config['to']}\n"
f"Subject: {email_config['subject']}\n"
f"\n"
f"{email_config['body']}"
)
# Write content to a temporary file to avoid shell quoting issues
with open('temp_email.txt', 'w', encoding='utf-8') as f:
f.write(email_content)
# Use cat to read the file and pipe to sendmail
result = subprocess.run(
'cat temp_email.txt | sendmail -t',
shell=True,
text=True,
capture_output=True,
check=False
)
# Clean up temp file
subprocess.run(['rm', 'temp_email.txt'], check=False)
if result.returncode == 0:
print(f"Successfully sent email to {email_config['to']}")
return True, ""
else:
error_msg = f"Failed to send email: {result.stderr}"
print(error_msg)
return False, result.stderr
except Exception as e:
error_msg = f"Error sending email: {str(e)}"
print(error_msg)
return False, str(e)
def send_all_test_emails() -> None:
"""Send all configured test emails and print results."""
print("\nSending test emails to verify end-to-end functionality...")
print("=" * 50)
success_count = 0
for email in TEST_EMAILS:
success, _ = send_test_email(email)
if success:
success_count += 1
time.sleep(2) # Wait 2 seconds between emails
print("\nSummary:")
print(f"Successfully sent {success_count} out of {len(TEST_EMAILS)} test emails")
print("=" * 50)
def send_single_test_email(email_type: str) -> None:
"""Send a single test email based on the email type (e.g., 'travel', 'deal')."""
matching_email = next((email for email in TEST_EMAILS if f"+{email_type}" in email["from"]), None)
if matching_email:
print(f"\nSending test email for {email_type} agent...")
print("=" * 50)
success, _ = send_test_email(matching_email)
print("=" * 50)
else:
print(f"No test email found for type: {email_type}")
if __name__ == "__main__":
import sys
if len(sys.argv) > 1:
send_single_test_email(sys.argv[1])
else:
send_all_test_emails()