This repository contains the Java-based Spring Boot backend for the Smart Email Writer application. It acts as a bridge between the user interface (Chrome Extension/Web App) and the Google Gemini AI, providing an API to generate context-aware email replies.
The backend is built using the following stack:
- Framework: Spring Boot 3.2.1
- Language: Java 17
- AI Integration: Google Gemini API (via Spring WebClient)
- Networking: Reactive WebClient for asynchronous API calls
Defines the structure of incoming data from the frontend.
emailContent: The original email body to be replied to.tone: The desired style for the response (e.g., Professional, Casual).
The core logic layer that communicates with Google's Generative Language API.
- Prompt Engineering: It constructs a specialized prompt instructing the AI to generate a reply based on the provided email content and tone.
- Response Parsing: It uses
ObjectMapperto traverse the complex JSON response from Gemini and extract only the generated text. - API Configuration: Dynamically fetches the API Key and URL from environment properties.
Exposes the REST endpoint for generation.
- Endpoint:
POST /api/email/generate. - CORS: Configured with
@CrossOriginto allow requests from the Chrome Extension and local development environments.
Endpoint: POST http://localhost:8080/api/email/generate
Request Body:
{
"emailContent": "Hi, are we still meeting today at 3 PM?",
"tone": "professional"
}
Response:
"Subject: Re: Meeting Confirmation
Dear [Name],
Yes, we are still scheduled to meet today at 3 PM. I look forward to our discussion.
Best regards, [Your Name]"
- JDK 17 or higher.
- Maven installed.
- A valid Google Gemini API Key.
- Navigate to
src/main/resources/application.properties. - Set your API key:
gemini.api.key=YOUR_ACTUAL_API_KEY
gemini.api.url=https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent
- Clone the repository.
- Run the following command in the terminal:
mvn spring-boot:run
//To Do
//To Do
//To Do