Spring Mail
- Spring abstraction over JavaMail API
- Used to send emails via SMTP
- Not implement SMTP, but use it
- Auto-configured by spring-boot-starter-mail
Spring Boot App
↓
JavaMailSender
↓
SMTP Server (SendGrid / MailHog)
↓
Recipient Mail Server
↓
Inbox (Gmail / Outlook)
SMTP (Simple Mail Transfer Protocol)
- A protocol used to send emails (like post office)
- Works at application layer
- Sending email from client → server
- Server → server forwarding
Does NOT:
- Read inbox
- Store emails long-term
- Provide UI
Best practice
- Async Email Sending
- @EnableAsync on main
- @Async on mail service method
- Do NOT send mail inside DB transaction
- If email fails → whole transaction rolls back.