-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_email_functionality.py
More file actions
298 lines (238 loc) · 9.83 KB
/
Copy pathtest_email_functionality.py
File metadata and controls
298 lines (238 loc) · 9.83 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/usr/bin/env python3
"""
Email Functionality Test
This script tests the core email functionality without requiring Frappe.
"""
import smtplib
import ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import sys
import os
def test_smtp_connection():
"""Test SMTP connection to the configured server"""
print("🧪 Testing SMTP Connection...")
# SMTP Configuration (from the CRM settings)
smtp_server = "smtpout.secureserver.net"
smtp_port = 465
username = "information@variphi.com"
password = "Nextneural@2402"
try:
# Create SSL context
context = ssl.create_default_context()
# Connect to SMTP server
print(f" Connecting to {smtp_server}:{smtp_port}...")
server = smtplib.SMTP_SSL(smtp_server, smtp_port, context=context)
# Login
print(f" Logging in with {username}...")
server.login(username, password)
# Test sending a simple email
print(" Sending test email...")
msg = MIMEMultipart()
msg['From'] = username
msg['To'] = username # Send to self for testing
msg['Subject'] = "SMTP Configuration Test"
msg.attach(MIMEText("This is a test email to verify SMTP configuration.", 'plain'))
server.send_message(msg)
server.quit()
print("✅ SMTP connection and email sending successful!")
return True
except smtplib.SMTPAuthenticationError as e:
print(f"❌ Authentication failed: {e}")
return False
except smtplib.SMTPConnectError as e:
print(f"❌ Connection failed: {e}")
return False
except smtplib.SMTPException as e:
print(f"❌ SMTP error: {e}")
return False
except Exception as e:
print(f"❌ Unexpected error: {e}")
return False
def test_email_template_content():
"""Test email template content"""
print("\n🔍 Checking Email Template Content...")
try:
template_path = "crm/templates/emails/crm_invitation.html"
with open(template_path, 'r') as f:
content = f.read()
print("✅ Email template file exists")
print(f" Template size: {len(content)} characters")
# Check for required template variables
required_vars = ['{{ invite_link }}', '{{ role }}', '{{ invited_by }}']
missing_vars = []
for var in required_vars:
if var not in content:
missing_vars.append(var)
if missing_vars:
print(f"⚠️ Missing template variables: {missing_vars}")
else:
print("✅ All required template variables found")
# Check for HTML structure
if '<html>' in content and '</html>' in content:
print("✅ HTML structure is valid")
else:
print("⚠️ HTML structure may be incomplete")
return len(missing_vars) == 0
except FileNotFoundError:
print("❌ Email template file not found")
return False
except Exception as e:
print(f"❌ Error reading template: {e}")
return False
def test_invitation_email_simulation():
"""Simulate sending an invitation email"""
print("\n📧 Simulating Invitation Email...")
# SMTP Configuration
smtp_server = "smtpout.secureserver.net"
smtp_port = 465
username = "information@variphi.com"
password = "Nextneural@2402"
try:
# Read email template
template_path = "crm/templates/emails/crm_invitation.html"
with open(template_path, 'r') as f:
template_content = f.read()
# Simulate template variables
invite_link = "https://example.com/invite/test123"
role = "Sales User"
invited_by = "System Administrator"
# Replace template variables
email_content = template_content.replace('{{ invite_link }}', invite_link)
email_content = email_content.replace('{{ role }}', role)
email_content = email_content.replace('{{ invited_by }}', invited_by)
print(" Template processed successfully")
# Create SSL context
context = ssl.create_default_context()
# Connect to SMTP server
server = smtplib.SMTP_SSL(smtp_server, smtp_port, context=context)
server.login(username, password)
# Create email message
msg = MIMEMultipart('alternative')
msg['From'] = username
msg['To'] = username # Send to self for testing
msg['Subject'] = f"Invitation to join CRM - {role}"
# Add HTML content
msg.attach(MIMEText(email_content, 'html'))
# Send email
server.send_message(msg)
server.quit()
print("✅ Invitation email simulation successful!")
return True
except Exception as e:
print(f"❌ Error in invitation email simulation: {e}")
return False
def test_email_configuration_files():
"""Test email configuration files exist"""
print("\n🔍 Checking Email Configuration Files...")
files_to_check = [
"crm/utils/email_config.py",
"crm/api/__init__.py",
"crm/fcrm/doctype/crm_invitation/crm_invitation.py",
"frontend/src/components/Settings/EmailConfiguration.vue",
"frontend/src/components/Settings/EmailDebug.vue"
]
all_exist = True
for file_path in files_to_check:
if os.path.exists(file_path):
print(f"✅ {file_path}")
else:
print(f"❌ {file_path} - Missing")
all_exist = False
return all_exist
def test_frontend_components():
"""Test frontend components exist and have proper structure"""
print("\n🔍 Checking Frontend Components...")
try:
# Check EmailConfiguration.vue
with open("frontend/src/components/Settings/EmailConfiguration.vue", 'r') as f:
config_content = f.read()
# Check for required elements
required_elements = [
'Test Email',
'Test Invitation',
'Configure Default',
'Custom SMTP Configuration'
]
missing_elements = []
for element in required_elements:
if element not in config_content:
missing_elements.append(element)
if missing_elements:
print(f"⚠️ Missing elements in EmailConfiguration.vue: {missing_elements}")
else:
print("✅ EmailConfiguration.vue has all required elements")
# Check EmailDebug.vue
with open("frontend/src/components/Settings/EmailDebug.vue", 'r') as f:
debug_content = f.read()
if 'Email Debug' in debug_content:
print("✅ EmailDebug.vue exists and has debug functionality")
else:
print("⚠️ EmailDebug.vue may be missing debug functionality")
return len(missing_elements) == 0
except Exception as e:
print(f"❌ Error checking frontend components: {e}")
return False
def main():
"""Run all tests"""
print("🚀 Starting Email Functionality Tests")
print("=" * 50)
tests = [
("SMTP Connection", test_smtp_connection),
("Email Template Content", test_email_template_content),
("Invitation Email Simulation", test_invitation_email_simulation),
("Email Configuration Files", test_email_configuration_files),
("Frontend Components", test_frontend_components),
]
results = {}
for test_name, test_func in tests:
print(f"\n📋 Running {test_name}...")
try:
result = test_func()
results[test_name] = result
if result:
print(f"✅ {test_name} passed")
else:
print(f"❌ {test_name} failed")
except Exception as e:
print(f"❌ {test_name} error: {str(e)}")
results[test_name] = False
# Summary
print("\n" + "=" * 50)
print("📊 Test Results:")
for test_name, result in results.items():
status = "✅ PASS" if result else "❌ FAIL"
print(f" {test_name}: {status}")
# Calculate success rate
passed = sum(results.values())
total = len(results)
success_rate = (passed / total) * 100
print(f"\n📈 Success Rate: {passed}/{total} ({success_rate:.1f}%)")
# Recommendations
print("\n💡 Recommendations:")
if not results.get("SMTP Connection", False):
print(" - Check SMTP server settings")
print(" - Verify email credentials")
print(" - Check firewall/network settings")
if not results.get("Email Template Content", False):
print(" - Ensure email template has all required variables")
print(" - Check template HTML structure")
if not results.get("Invitation Email Simulation", False):
print(" - Check email template processing")
print(" - Verify SMTP configuration")
if not results.get("Email Configuration Files", False):
print(" - Ensure all email configuration files exist")
print(" - Check file paths and permissions")
if not results.get("Frontend Components", False):
print(" - Check frontend component structure")
print(" - Verify Vue.js components")
if success_rate >= 80:
print("\n🎉 Overall Status: GOOD - Email functionality is mostly working!")
elif success_rate >= 60:
print("\n⚠️ Overall Status: FAIR - Some issues need attention")
else:
print("\n❌ Overall Status: POOR - Significant issues need fixing")
return success_rate >= 80
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)