-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_basic_smtp.py
More file actions
131 lines (99 loc) · 3.6 KB
/
test_basic_smtp.py
File metadata and controls
131 lines (99 loc) · 3.6 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
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python3
"""
Simple test for basic aiosmtpd server.
"""
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from datetime import datetime
def test_basic_smtp(host='localhost', port=1031):
"""Test basic SMTP connection."""
try:
print(f"Testing connection to {host}:{port}...")
# Create SMTP connection
server = smtplib.SMTP(host, port)
server.set_debuglevel(1) # Enable debug output
# Say hello
server.helo('test-client')
# Get server capabilities
code, response = server.docmd('EHLO', 'test-client')
print(f"EHLO response: {code} - {response}")
server.quit()
print("✅ Basic connection test successful!")
return True
except Exception as e:
print(f"❌ Connection test failed: {e}")
return False
def test_send_email(host='localhost', port=1031):
"""Test sending an email."""
try:
print(f"Sending test email...")
# Create message
msg = MIMEMultipart()
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
msg['Subject'] = f'Basic Test Email - {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}'
# Email body
body = f"""
This is a basic test email sent to the aiosmtpd server.
Timestamp: {datetime.now().isoformat()}
If you see this in the server console output, the basic server is working!
Best regards,
Test Script
"""
msg.attach(MIMEText(body, 'plain'))
# Send email
server = smtplib.SMTP(host, port)
server.set_debuglevel(1)
# Send the email
text = msg.as_string()
server.sendmail('[email protected]', '[email protected]', text)
server.quit()
print("✅ Test email sent successfully!")
print("📧 Check the server console for the email content.")
return True
except Exception as e:
print(f"❌ Failed to send test email: {e}")
return False
def main():
"""Run basic tests."""
print("🧪 Basic aiosmtpd Test Suite")
print("=" * 40)
# Configuration
host = 'localhost'
port = 1031
print(f"Testing basic aiosmtpd server on {host}:{port}")
print("Make sure the basic server is running with: python test_basic_aiosmtpd.py")
print()
# Run tests
tests = [
("Basic Connection", lambda: test_basic_smtp(host, port)),
("Send Test Email", lambda: test_send_email(host, port)),
]
results = []
for test_name, test_func in tests:
print(f"\n🔍 Running: {test_name}")
print("-" * 30)
try:
result = test_func()
results.append((test_name, result))
except Exception as e:
print(f"❌ Test failed with exception: {e}")
results.append((test_name, False))
# Summary
print("\n" + "=" * 40)
print("📊 Test Results Summary")
print("=" * 40)
passed = 0
for test_name, result in results:
status = "✅ PASS" if result else "❌ FAIL"
print(f"{test_name}: {status}")
if result:
passed += 1
print(f"\nOverall: {passed}/{len(results)} tests passed")
if passed == len(results):
print("🎉 All tests passed! The basic aiosmtpd server is working correctly.")
else:
print("⚠️ Some tests failed. Check the configuration.")
if __name__ == "__main__":
main()