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.
✨ 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!
- 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)
- Added full CRUD endpoints for mail templates (create, update, delete, preview)
- Introduced Joi validators for template create/update/preview
- Updated routes/controller to support ID and type lookups
- Built React Templates page with HTML editor, preview, and clipboard helpers
- Added navigation entry and route for /templates
- Enhanced documentation (README, QUICKSTART, KULLANIM, frontend/backend README)