GMailReceiver is a Spring Boot application that displays emails in a user-friendly inbox UI and integrates seamlessly with GMailSender to send emails. It allows users to view, compose, and manage emails with ease. The service provides a clean and responsive interface for email operations.
- Java 17+
- Spring Boot 3.x
- Spring Web, Spring MVC
- Thymeleaf (UI templates)
- RestTemplate (for calling GMailSender service)
- Bootstrap 5 (frontend styling)
- Maven
- Display received emails in Inbox, Starred, Sent, Spam, and Bin folders.
- Compose and send emails via GMailSender REST API.
- Show success/error messages after sending emails.
- Back to Inbox button after sending emails.
- Responsive UI with table and modal forms for email operations.
Update src/main/resources/application.properties with your settings:
spring.application.name=GEmailReceiver
# Gmail IMAP settings (for reading emails)
spring.mail.host=imap.gmail.com
spring.mail.port=993
spring.mail.username=your-email@gmail.com
spring.mail.password=your-app-password
# GMailSender service URL
gmailsender.url=http://localhost:8081Emails may look simple on the surface, but under the hood, there’s a robust system of protocols that move messages reliably across the internet.
This document explains how sending and receiving emails actually works — from the sender’s outbox to the receiver’s inbox.
When you send or receive an email, several servers and protocols come into play:
- SMTP (Simple Mail Transfer Protocol) → handles sending emails.
- IMAP (Internet Message Access Protocol) → handles retrieving emails (keeps mail synced across devices).
- POP3 (Post Office Protocol v3) → also retrieves emails, but downloads and usually removes them from the server.
These protocols are layered on top of TCP/IP, and they use well-defined ports and security standards (like SSL/TLS).
SMTP is the workhorse for sending emails.
It’s used by your mail client (like Gmail, Outlook, or Thunderbird) to deliver messages to the mail server — and by mail servers themselves to relay messages between domains.
- User writes an email in a client (MUA — Mail User Agent).
- The MUA connects to an SMTP server (MSA — Mail Submission Agent) using:
- Port 587 (with STARTTLS) or 465 (with SSL/TLS).
- The MSA validates the user and forwards the email to the Mail Transfer Agent (MTA).
- The MTA looks up the recipient’s domain via DNS MX (Mail Exchange) records.
- The email is routed across the internet, possibly hopping through multiple MTAs.
- Finally, the recipient’s Mail Delivery Agent (MDA) stores the email in their mailbox on the destination mail server.
In short:
Once the email reaches the recipient’s mail server, the user can fetch it using either IMAP or POP3.
IMAP keeps your emails on the server and synchronizes changes (read/unread, folders, flags) across multiple devices.
- Default ports:
143(IMAP)993(IMAPS - IMAP over SSL)
- Best for multi-device users — mobile, laptop, webmail, etc.
Flow:
When you open an email on your phone, it’s not downloaded — you’re viewing it remotely.
Delete or move it, and the change reflects everywhere.
POP3 is older and simpler — it downloads emails from the server and (by default) removes them afterward.
- Default ports:
110(POP3)995(POP3S - over SSL)
- Great for single-device setups, less ideal for modern multi-device use.
Flow:
Some clients can be configured to “leave a copy on the server,” but that’s a workaround — IMAP handles this natively.
Modern email systems always wrap these protocols in encryption:
| Protocol | Default Port | Secure Port (SSL/TLS) |
|---|---|---|
| SMTP | 25 / 587 | 465 |
| IMAP | 143 | 993 |
| POP3 | 110 | 995 |
Authentication uses either:
- LOGIN / PLAIN (basic, often over TLS)
- OAuth 2.0 (modern, token-based — used by Gmail, Outlook, etc.)
Let’s say Alice sends an email to Bob:
- Alice’s mail client connects to
smtp.gmail.com:587. - Gmail’s MTA looks up Bob’s domain’s MX record — say
mx.outlook.com. - Gmail’s server sends the message to Outlook’s mail server.
- Outlook stores it in Bob’s mailbox.
- Bob’s phone connects to
imap.outlook.com:993and retrieves/syncs the email.
“Email’s been around since the ‘70s — the tech is old, but it’s rock-solid once you understand the moving parts.”
This project is licensed under the MIT License.
