Skip to content

Commit fb13818

Browse files
authored
Merge pull request #819 from layer5io/leecalcote-patch-1
Add Email/SMS Troubleshooting Guide for Layer5 Cloud
2 parents 26cf9cc + d65070a commit fb13818

1 file changed

Lines changed: 259 additions & 0 deletions

File tree

  • content/en/cloud/self-hosted/operating
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
---
2+
title: Email / SMTP Troubleshooting
3+
categories: [Self-Hosted]
4+
description: >
5+
This guide explains how to diagnose email sending issues in Layer5 Cloud deployments using the enhanced debug logging and testing features.
6+
---
7+
8+
# Email Debugging Guide for Layer5 Cloud
9+
10+
This guide explains how to diagnose email sending issues in Layer5 Cloud deployments using the enhanced debug logging and testing features.
11+
12+
## Overview
13+
14+
Email issues in Layer5 Cloud can occur due to various reasons including SMTP configuration problems, template errors, recipient validation issues, or network connectivity problems. This guide provides comprehensive debugging tools and techniques.
15+
16+
## Debug Log Levels
17+
18+
To enable email debugging, set the `LOG_LEVEL` environment variable to `5` (Debug) or `6` (Trace):
19+
20+
```bash
21+
# In config.env or environment variables
22+
LOG_LEVEL=5
23+
```
24+
25+
## Testing Email Configuration
26+
27+
### 1. Email Configuration Test Endpoint
28+
29+
Test the basic email configuration without sending actual emails:
30+
31+
```bash
32+
curl -X GET "https://your-domain.com/api/system/email/test"
33+
```
34+
35+
**Expected Response (Success):**
36+
```json
37+
{
38+
"status": "success",
39+
"message": "Email configuration is valid",
40+
"timestamp": "1695312000",
41+
"smtp_host": "smtp.gmail.com",
42+
"smtp_port": "587",
43+
"smtp_username": "your-email@domain.com"
44+
}
45+
```
46+
47+
**Expected Response (Error):**
48+
```json
49+
{
50+
"error": "Email configuration test failed: SMTP_HOST environment variable is not set"
51+
}
52+
```
53+
54+
### 2. Authenticated Email Send Test (Provider Admin Only)
55+
56+
Send an actual test email to verify end-to-end email functionality. This endpoint requires authentication and provider admin role:
57+
58+
```bash
59+
curl -X POST "https://cloud.layer5.io/api/system/email/test" \
60+
-H "Content-Type: application/json" \
61+
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
62+
-d '{
63+
"to": "test@example.com",
64+
"subject": "Layer5 Cloud Email Test"
65+
}'
66+
```
67+
68+
**Request Body:**
69+
```json
70+
{
71+
"to": "test@example.com",
72+
"subject": "Layer5 Cloud Email Test (optional)"
73+
}
74+
```
75+
76+
**Expected Response (Success):**
77+
```json
78+
{
79+
"status": "success",
80+
"message": "Test email sent successfully",
81+
"timestamp": "1695312000",
82+
"sent_to": "test@example.com"
83+
}
84+
```
85+
86+
**Expected Response (Error - Unauthorized):**
87+
```json
88+
{
89+
"error": "Unauthorized: provider admin role required"
90+
}
91+
```
92+
93+
**Expected Response (Error - Invalid Email):**
94+
```json
95+
{
96+
"error": "Invalid email address format"
97+
}
98+
```
99+
100+
**Expected Response (Error - Email Configuration):**
101+
```json
102+
{
103+
"error": "Email configuration validation failed: SMTP authentication failed"
104+
}
105+
```
106+
107+
### 3. Required Environment Variables
108+
109+
Ensure all SMTP environment variables are properly configured:
110+
111+
```bash
112+
# Required SMTP Configuration
113+
SMTP_HOST=smtp.gmail.com
114+
SMTP_PORT=587
115+
SMTP_USERNAME=your-email@domain.com
116+
SMTP_PASSWORD=your-app-password
117+
```
118+
119+
## Debug Log Examples
120+
121+
When `LOG_LEVEL=5`, you'll see detailed debug logs for email operations:
122+
123+
### 1. SMTP Configuration Validation
124+
125+
```log
126+
DEBUG SMTP Configuration Debug host=smtp.gmail.com port=587 username=user@domain.com password_set=true password_length=16
127+
```
128+
129+
### 2. Template Processing
130+
131+
```log
132+
DEBUG Email template parsing template_paths=[email-templates/meshery-cloud/email.body.gotmpl, ...] template_count=5 base_template_path=email-templates/meshery-cloud/email.body.gotmpl
133+
DEBUG Email template parsed successfully template_name=email.body.gotmpl
134+
DEBUG Executing email template email_type=welcome recipients=user@example.com has_org_vars=true org_name=MyOrg
135+
DEBUG Email template executed successfully body_length=2048 email_type=welcome
136+
```
137+
138+
### 3. Email Construction and Sending
139+
140+
```log
141+
DEBUG Email construction completed final_email_size=2156 has_cc=false cc_count=0 recipient_count=1
142+
DEBUG Attempting SMTP send smtp_endpoint=smtp.gmail.com:587 from_user=sender@domain.com to_recipients=[user@example.com] email_size_bytes=2156
143+
INFO Email sent successfully recipients=user@example.com subject="Welcome to Layer5 Cloud"
144+
```
145+
146+
### 4. Error Scenarios
147+
148+
```log
149+
ERROR SMTP send failed - detailed error info error_type=*net.OpError error_message="dial tcp: lookup smtp.gmail.com: no such host" smtp_host=smtp.gmail.com smtp_port=587 smtp_username=sender@domain.com recipients=[user@example.com]
150+
```
151+
152+
## Flow Emails (Kratos Integration)
153+
154+
Flow emails (registration, password recovery, etc.) use a separate logging mechanism. When debugging flow emails, look for logs with `[DEBUG]` and `[ERROR]` prefixes:
155+
156+
```log
157+
[DEBUG] Flow email attempt - Host: smtp.gmail.com, Port: 587, Username: sender@domain.com, Password set: true
158+
[DEBUG] Flow email - Subject template: valid/email-recover-subject.gotmpl, Body template: valid/email-recover.html, Recipient: user@example.com
159+
[DEBUG] Flow email subject template parsed successfully
160+
[DEBUG] Flow email subject generated: Recover access to your account
161+
[DEBUG] Flow email body generated, length: 1024
162+
[DEBUG] Flow email constructed, total size: 1200 bytes
163+
[DEBUG] Flow email attempting send to SMTP: smtp.gmail.com:587
164+
[SUCCESS] Flow email sent successfully to: user@example.com
165+
```
166+
167+
## Common Issues and Solutions
168+
169+
### 1. SMTP Configuration Errors
170+
171+
**Issue:** `SMTP configuration error: SMTP_HOST is empty`
172+
173+
**Solution:**
174+
- Verify all SMTP environment variables are set
175+
- Check that environment variables are properly loaded in your deployment
176+
- Use the test endpoint to validate configuration
177+
178+
### 2. Authentication Failures
179+
180+
**Issue:** `SMTP authentication failed for user 'sender@domain.com'`
181+
182+
**Solution:**
183+
- Verify SMTP username and password are correct
184+
- For Gmail, use App Passwords instead of regular passwords
185+
- Check if 2FA is enabled and properly configured
186+
187+
### 3. Template Errors
188+
189+
**Issue:** `Email template missing or inaccessible`
190+
191+
**Solution:**
192+
- Verify email template files exist in `config/email-templates/`
193+
- Check file permissions
194+
- Validate template syntax and required variables
195+
196+
### 4. Recipient Validation Errors
197+
198+
**Issue:** `Email recipient validation failed`
199+
200+
**Solution:**
201+
- Verify email addresses are valid and properly formatted
202+
- Check for empty recipient lists
203+
- Validate email addresses contain `@` symbol
204+
205+
### 5. Network Connectivity Issues
206+
207+
**Issue:** `dial tcp: lookup smtp.gmail.com: no such host`
208+
209+
**Solution:**
210+
- Check network connectivity to SMTP server
211+
- Verify firewall rules allow SMTP traffic
212+
- Test DNS resolution for SMTP host
213+
214+
## Development Mode
215+
216+
In development environment (`ENVIRONMENT=development`), email content is logged instead of being sent:
217+
218+
```log
219+
INFO Development mode - Email details recipients=user@example.com subject="Test Email" body="<html>...</html>"
220+
```
221+
222+
## Error Codes Reference
223+
224+
| Error Code | Description | Common Causes |
225+
|------------|-------------|---------------|
226+
| meshery_cloud-1092 | Failed to send email | Network issues, SMTP server down |
227+
| meshery_cloud-1144 | SMTP authentication failed | Invalid credentials |
228+
| meshery_cloud-1145 | SMTP send mail error | Server rejection, quota exceeded |
229+
| meshery_cloud-1146 | SMTP configuration error | Missing environment variables |
230+
| meshery_cloud-1147 | Email template missing | Template files not found |
231+
| meshery_cloud-1148 | Email recipient validation failed | Invalid email addresses |
232+
233+
## Monitoring and Alerting
234+
235+
Consider setting up monitoring for email-related metrics:
236+
237+
1. **Email Send Success Rate**: Monitor successful vs failed email sends
238+
2. **SMTP Response Times**: Track SMTP server response times
239+
3. **Template Processing Time**: Monitor email template rendering performance
240+
4. **Configuration Validation**: Regular health checks for email configuration
241+
242+
## Best Practices
243+
244+
1. **Use Debug Logs Sparingly**: Only enable debug logging when troubleshooting
245+
2. **Secure Credentials**: Never log SMTP passwords in plaintext
246+
3. **Regular Testing**: Use the test endpoint to validate configuration regularly
247+
4. **Monitor Quotas**: Keep track of email service provider quotas and limits
248+
5. **Template Validation**: Test email templates thoroughly before deployment
249+
250+
## Troubleshooting Checklist
251+
252+
- [ ] Check `LOG_LEVEL` is set to 5 or 6 for debug logging
253+
- [ ] Verify all SMTP environment variables are configured
254+
- [ ] Test email configuration using `/api/system/email/test` endpoint
255+
- [ ] Check network connectivity to SMTP server
256+
- [ ] Validate email template files exist and are accessible
257+
- [ ] Verify recipient email addresses are valid
258+
- [ ] Check SMTP server logs for additional error details
259+
- [ ] Monitor email service provider quotas and limits

0 commit comments

Comments
 (0)