An intelligent, lightweight Spring Boot API that automatically replies to incoming emails based on message keywords using FreeMarker HTML templates.
Developed with ❤️ for DtPix Studios
- Automatically detects keywords like
pricing,services, andsupport - Sends pre-defined HTML responses via Gmail SMTP
- Uses FreeMarker for dynamic templating
- Minimalistic single-endpoint API
- Fully customizable email templates
- Java 21+
- Spring Boot 3.x
- JavaMailSender
- FreeMarker Templates
- Gmail SMTP
POST /api/email/send-auto-response
Receives a JSON payload with senderEmail, subject, and message. Responds automatically based on detected keywords in the message.
{
"senderEmail": "client@example.com",
"subject": "Need pricing info",
"message": "Hi team, could you please share pricing details?"
}Auto-response sent successfully!
Error: senderEmail and message are required fields.
The keyword in the message body determines which template to use:
| Keyword | Template File |
|---|---|
| pricing | pricing.ftl |
| services | services.ftl |
| support | support.ftl |
| (default) | default_response_template.ftl |
Templates are stored in:
src/main/resources/templates/
bash
git clone https://github.com/Hariharan1893/Auto-Email-Responder-Api.git
cd Auto-Email-Responder-Api
sql
CREATE DATABASE email_responder_db;
Make sure to provide your Gmail and DB credentials.
bash
./mvnw spring-boot:run
Or if you’re using Maven directly:
bash
mvn clean install
mvn spring-boot:run
Ensure your application.yml or application.properties contains:
server:
port: 8080
spring:
datasource:
url: jdbc:mysql://localhost:3306/your-db
username: root
password: your-db-password
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: update
show-sql: true
database-platform: org.hibernate.dialect.MySQL8Dialect
mail:
host: smtp.gmail.com
port: 587
username: your-company-mail
password: your-app-password
properties:
mail:
smtp:
auth: true
starttls:
enable: true
required: true
connectiontimeout: 5000
timeout: 5000
writetimeout: 5000
freemarker:
template-loader-path: classpath:/templates/
suffix: .ftl
charset: UTF-8
logging:
level:
org:
springframework:
web: DEBUG
mail: DEBUG
You must use an App Password if your Gmail has 2FA enabled.
curl -X POST http://localhost:8080/api/email/send-auto-response \
-H "Content-Type: application/json" \
-d '{
"senderEmail": "client@example.com",
"subject": "Looking for services",
"message": "Can you provide more info on your services?"
}'📧 hariramesh1893@gmail.com
🌐 Hariharan