Enhanced system prompt:
- Professional cyber security expert role
- Modern HTML/CSS styling instructions
- Responsive design requirements
- Persuasive and urgent tone guidance
- Turkish language grammar emphasis
- Realistic corporate email appearance
Enhanced user prompt:
- Better structured input with emojis (📌)
- Clear field labels (HEDEF ŞİRKET, SENARYO, etc.)
- Detailed HTML example with inline CSS
- Button styling, footer, responsive design
- Max 70 char subject line guidance
- Multiple warnings for quality output
All user inputs are sent to AI:
✅ company_name (Şirket Adı)
✅ scenario (Senaryo)
✅ employee_info (Çalışan Bilgisi) - optional
✅ custom_prompt (Ek Talimatlar) - optional
template_name and template_type are for DB only, NOT sent to AI.
This will produce much higher quality, styled HTML emails.
Fixed double .data access in template preview:
- Changed response.data.data.rendered_html
- To response.data.rendered_html
templateService already returns response.data, no need to access .data twice.
The bug was in field mapping when saving AI-generated templates:
- Changed 'type' to 'template_type' (correct column name)
- Changed 'body_template' to 'body_html' (correct column name)
This fixes the 400 Bad Request validation error:
'notNull Violation: MailTemplate.template_type cannot be null'
Now AI template generation works correctly.
Database Changes:
- Remove UNIQUE constraint from mail_templates.template_type
- Allow multiple templates with same type (e.g., multiple bank templates)
Ollama Service Improvements:
- Add detailed logging for AI responses (first 500 chars)
- Check multiple field name variations (subject/Subject/konu/title, body/Body/html/content)
- Improve error messages with actual field names
- Better JSON parsing with fallback
- Clearer prompt instructions to AI
This fixes:
- 400 Validation Error when creating templates with existing type
- AI response parsing issues with different field names
- Auto-save settings before testing connection
- Make model list clickable for easy selection
- Models auto-populate when clicked
- Better user experience for Ollama configuration
Now users can click on a model from the list to select it instantly.
✨ New Features:
- 🤖 AI-powered mail template generation with Ollama
- 📧 Test mail sending with preview
- 🔧 Ollama server and model management
- 🎨 Beautiful AI generation dialog in Templates page
- ⚙️ Ollama settings panel with connection test
Backend:
- Add ollama.service.js - Ollama API integration
- Add ollama.controller.js - Template generation endpoint
- Add ollama.routes.js - /api/ollama/* routes
- Support for multiple Ollama models (llama3.2, mistral, gemma)
- JSON-formatted AI responses with subject + HTML body
- Configurable server URL and model selection
Frontend:
- Settings: Ollama configuration panel
- Server URL input
- Model selection
- Connection test with model listing
- Templates: AI generation dialog
- Company name, scenario, employee info inputs
- Custom prompt for AI instructions
- Auto-save to database
- Test mail sending functionality
Documentation:
- OLLAMA_SETUP.md - Comprehensive setup guide
- Installation instructions
- Model recommendations
- Usage examples
- Troubleshooting
Tech Stack:
- Ollama API integration (REST)
- Axios HTTP client
- React dialogs with MUI
- Self-hosted AI (privacy-friendly)
- Zero external API dependencies
Example Usage:
Company: Garanti Bankası
Scenario: Account security warning
→ AI generates professional phishing test mail in seconds!
- testConnection now sends a real test email to the configured Gmail address
- User receives actual email confirmation that setup works
- Email contains success message and system info
- Google provides App Password with spaces (e.g. 'abcd efgh ijkl mnop')
- Backend now automatically removes all spaces before saving
- Users can paste password directly from Google without manual cleanup
- Also trim gmail_user for safety
- Changed gmail_password to gmail_app_password in request body destructuring
- Matches frontend Settings.jsx which sends gmail_app_password
- Backend still stores as 'gmail_password' key in database (for backward compatibility)
- Fixed handleSave to use separate /gmail and /telegram endpoints
- Changed /test-mail to /test-gmail endpoint
- Added proper null checks in loadSettings to prevent uncontrolled input warnings
- Settings now properly saved to backend with correct endpoint structure
- Updated templateService to return response.data like other services
- Added fallback to empty array in Templates.jsx to prevent map errors
- Ensures consistency across all service modules
- Fixed AuthContext to properly set user to null on auth check failure
- Added loading spinner in PrivateRoute instead of returning null
- Removed automatic redirect from API interceptor (let React Router handle it)
- Improved error handling in checkAuth to prevent stuck loading state