Skip to content

Latest commit

Β 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Mail'O βœ‰οΈπŸ€–

Mail'O is a professional, AI-powered email writing assistant designed to streamline the process of drafting polished, context-aware emails. By entering a recipient's name, a brief description of the message, and selecting a desired tone, users can instantly generate high-quality email drafts. Mail'O is built with a modern React frontend and a robust Java Spring Boot backend, utilizing Spring AI to communicate with Google's Gemini models for prompt completion and content generation.


πŸ“Έ Application Showcase

Note

The screenshots below illustrate the responsive UI, tone-switching features, and generated email drafts. Please place your actual screenshots in the docs/screenshots/ folder to activate the visual showcase.

Home Page

Home Page

How It Works Page

How It Works

Email Generator Page (Output)

Email Generator Output


✨ Features

  • AI-Powered Email Generation: Formulates structured, context-aware email subjects and bodies using Google's Gemini model.
  • Multiple Email Tones: Establishes context-appropriate greetings and writing styles based on the selected tone:
    • Professional: Formal, structured, business-ready language.
    • Simple & Direct: Fluff-free, clear, and concise messaging.
    • Friendly: Conversational, warm, and approachable language.
  • Recipient and Context Customization: Tailors the email's greetings, style, and sign-offs dynamically based on the recipient's identity and description.
  • Input Validation: Enforces parameters on both frontend fields and backend DTOs to maintain database and API integrity.
  • Actionable Output: Includes one-click copy to clipboard and a pre-filled compose button to export drafts directly to Gmail.
  • Responsive User Interface: Features a responsive layout with theme toggle (Light and Dark mode) using Tailwind CSS and DaisyUI.
  • API Documentation: Integrates Swagger UI/OpenAPI to allow developers to interact with the endpoints directly.

πŸ’‘ How It Works

  1. User Input: The user inputs the recipient's name, selects a tone, describes the email's content (minimum 10 characters), and submits the form.
  2. Frontend Validation: React validates the input lengths and formatting to prevent invalid API requests.
  3. HTTP POST Request: Axios transmits the validated data in JSON format to the /api/generateMail endpoint.
  4. Backend Bean Validation: Spring Boot interceptors validate the incoming request properties against Jakarta Bean Validation annotations.
  5. Service Processing: The backend service layer constructs a structured instruction prompt containing the name, description, selected tone, and today's date.
  6. Spring AI Chat Client: The ChatClient formats and transmits the prompt securely to the Google Gemini model.
  7. AI Generation: Google Gemini analyzes the prompt and returns a tailored subject line and email body.
  8. UI Rendering & Toasts: The backend returns the email payload, React updates the local states to display the split subject/body layout, and triggers a success toast notification.

πŸ—οΈ Architecture

graph TD
    classDef client fill:#3b82f6,stroke:#1d4ed8,stroke-width:2px,color:#fff;
    classDef server fill:#10b981,stroke:#047857,stroke-width:2px,color:#fff;
    classDef external fill:#f59e0b,stroke:#d97706,stroke-width:2px,color:#fff;

    A[React Frontend]:::client -->|Axios HTTP POST| B[Spring Boot REST API]:::server
    B -->|Jakarta Bean Validation| C[AppController]:::server
    C -->|MailRequest DTO| D[AppService]:::server
    D -->|Spring AI ChatClient| E[Google Gemini API]:::external
    E -->|Generated Email Response| D
    D -->|MailResponse DTO| C
    C -->|JSON Payload Response| A
Loading

πŸ› οΈ Technology Stack

Frontend

  • React 19 - User interface rendering
  • Vite 8 - Frontend building and local dev server
  • Tailwind CSS v3 - Utility-first styling framework
  • DaisyUI v4 - Tailwind-based UI components
  • React Router v7 - Client-side page navigation
  • Axios - HTTP client request handling
  • React Hot Toast - Non-blocking system notifications
  • React Icons - Vector icons library

Backend

  • Java 21 - Runtime environment and compile target
  • Spring Boot 4.1.1 - Main application framework
  • Spring Web MVC - RESTful controller endpoints routing
  • Spring AI (Google GenAI Starter v2.0.0) - Model configuration and prompt management
  • Jakarta Bean Validation - DTO attribute validation
  • Springdoc OpenAPI v3 (v3.0.3) - Automated Swagger documentation
  • Lombok - Automatic builder, getter, and setter generation
  • Maven - Build tool and dependency manager

AI Model

  • Google Gemini 3.6 Flash (gemini-3.6-flash)

🧠 AI Integration

Mail'O leverages Google's gemini-3.6-flash model through the Spring AI framework. In the backend AppService.java class, the application compiles user input into a clean instruction prompt:

Write an email based on the following instructions:

From Name: Rajeev
Recipient Name: [toName]
Tone: [tone]
Today's Date: [currentDate]
Description of what to say: [description]

Please provide a suitable Subject line, followed by the email body. 
Address the email to the recipient provided. Use [Your Name] as a placeholder for the sender.
Do not include any extra conversational text outside of the email itself.

The model returns a plain text response containing the subject and body. The frontend parses this structure using a newline search to display the Subject and Body in separate copy-friendly fields.


πŸ“ Project Structure

Mail'O/
β”œβ”€β”€ client/                 # React Frontend (Vite)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/     # Reusable UI components (Navbar, EmailForm, EmailResult, ThemeToggle)
β”‚   β”‚   β”œβ”€β”€ layouts/        # Layout wrappers (MainLayout)
β”‚   β”‚   β”œβ”€β”€ pages/          # Full page views (Home, EmailGenerator, Features, NotFound)
β”‚   β”‚   β”œβ”€β”€ services/       # Network API services (emailService.js)
β”‚   β”‚   └── main.jsx        # Frontend entry point
β”‚   β”œβ”€β”€ package.json        # Frontend scripts and dependencies
β”‚   └── vite.config.js      # Vite build settings
β”‚
└── server/                 # Spring Boot Backend (Maven)
    β”œβ”€β”€ src/main/java/com/rj/mailO/
    β”‚   β”œβ”€β”€ config/         # System configurations (CorsConfig)
    β”‚   β”œβ”€β”€ controller/     # REST Endpoint controllers (AppController)
    β”‚   β”œβ”€β”€ dto/            # Data Transfer Objects (MailRequest, MailResponse)
    β”‚   └── service/        # AI prompt handling and business services (AppService)
    β”œβ”€β”€ src/main/resources/
    β”‚   └── application.properties # Server properties and Spring AI model variables
    └── pom.xml             # Maven dependencies configuration

πŸš€ Getting Started

Prerequisites

Make sure you have the following installed on your machine:

  • Node.js (v18.0.0 or higher)
  • JDK 21
  • Google Gemini API Key (Obtain one from Google AI Studio)

Environment Variables

Configure your credentials in the server folder. Create a .env file in server/:

GEMINI_API_KEY=your_actual_gemini_api_key_here

Warning

Security Warning: Never commit your .env file or raw API keys to Git. The project's root .gitignore file is pre-configured to ignore all .env files.

Backend Setup (Spring Boot)

  1. Navigate to the server directory:
    cd server
  2. Start the Spring Boot server using the Maven wrapper:
    • Windows:
      ./mvnw.cmd spring-boot:run
    • macOS/Linux:
      ./mvnw spring-boot:run
    The server will start at http://localhost:8080.

Frontend Setup (React)

  1. Navigate to the client directory:
    cd client
  2. Install the required packages:
    npm install
  3. Launch the Vite local server:
    npm run dev
    The application will run locally at http://localhost:5173.

πŸ“– Usage

  1. Open the application by visiting http://localhost:5173.
  2. Go to the Email Generator page.
  3. Enter the Recipient Name (e.g., Hiring Manager, Support Team).
  4. Enter the Email Description explaining what the email is about (minimum 10 characters).
  5. Select a Tone (Professional, Simple & Direct, or Friendly).
  6. Click Generate AI Email.
  7. Review the subject line and body output.
  8. Click Copy to copy the content to your clipboard, or Send Email to open the pre-filled message in Gmail.

πŸ›‘οΈ Validation & Error Handling

To maintain data integrity and avoid unnecessary AI API consumption, validation rules are enforced at both layers:

Validation Rules (MailRequest.java)

  • toName (@NotNull): The recipient name field is required and cannot be null.
  • description (@NotBlank, @Size): The description field is required and must contain between 10 and 2000 characters.
  • tone (@NotNull): A valid tone parameter matching one of the ToneEnum values is required.

Error Propagation

  • HTTP 400 Bad Request: If any validation rules are breached, the backend rejects the payload and returns an error array with descriptions.
  • Frontend Alerts: The Axios service layer catches HTTP failures, formats nested validation constraints, and surfaces them using React Hot Toast messages and a visual error banner in the UI.

πŸ”Œ API Documentation

  • Swagger Interactive UI: http://localhost:8080/swagger-ui/index.html
  • OpenAPI Specification JSON: http://localhost:8080/v3/api-docs

Email Generation Endpoint

  • Endpoint: /api/generateMail
  • Method: POST
  • Content-Type: application/json

Request Parameters

Field Type Required Description / Constraints
toName String Yes Name of the recipient
description String Yes Core email context (10 to 2000 characters)
tone String Yes Selected tone: PROFESSIONAL, SIMPLE, FRIENDLY

Request Payload

{
  "toName": "Support Team",
  "description": "Requesting an extension on the project deadline due to server downtime.",
  "tone": "PROFESSIONAL"
}

Response Payload (HTTP 200 OK)

{
  "result": "Subject: Request for Deadline Extension - Server Downtime\n\nDear Support Team,\n\nI hope this email finds you well. I am writing to request a short extension on the project deadline..."
}

πŸš€ Deployment

Frontend Build

To package the React frontend, navigate to the client/ directory and run:

npm run build

This generates optimized, minified production assets in the client/dist/ directory.

Backend Package

To package the Spring Boot backend into an executable JAR, navigate to the server/ directory and run:

./mvnw clean package

The standalone executable JAR will be generated under server/target/.

Production Considerations

When deploying to cloud providers:

  • Configure the database or target profiles using Spring profiles (spring.profiles.active).
  • Ensure that the GEMINI_API_KEY is configured as a secure system environment variable rather than hardcoded.

πŸ—ΊοΈ Roadmap

  • AI email generation using Google Gemini model
  • Multiple email tones (Professional, Simple, Friendly)
  • Jakarta Bean DTO validation and Axios error formatting
  • Direct clipboard copy integration
  • Responsive layout with Light/Dark mode switcher
  • Email history persistence (Database integration)
  • OAuth2 Authentication (Google/GitHub sign-in)
  • Direct Gmail API integration (Drafting/sending without redirects)
  • Multi-LLM provider support (switching between OpenAI, Anthropic, Gemini)
  • RAG-based email replies using historical threads or files

🀝 Contributing

  1. Fork the repository.
  2. Create a feature branch: git checkout -b feature/your-feature-name.
  3. Commit your changes: git commit -m 'Add some feature'.
  4. Push to the branch: git push origin feature/your-feature-name.
  5. Submit a Pull Request.

πŸ“„ License

No license is currently specified for this project.

About

An AI-powered email writing assistant built with React and Spring Boot. Leveraging Spring AI and Google's Gemini models, Mail'O generates professional, simple, or friendly email drafts in seconds based on custom recipient and context details. Includes robust request validation, toast notifications, theme toggling, and built-in Swagger docs.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages