Email Service Responsibilities and Integration Surface
src/main/java/com/bankasap/service/EmailService.java
src/main/java/com/bankasap/service/AuthService.java
src/main/java/com/bankasap/controller/AuthController.java
Overview
EmailService is the transactional mail layer for Bank ASAP. It builds SimpleMailMessage instances and sends them through the injected JavaMailSender, which gives the application a single place for outbound email delivery.
In the provided source surface, the service is used to support two authentication-related mail flows: sending a one-time verification code for sign-up and login, and exposing a separate account-lock notification method. The mail content is hard-coded in the service, so the integration surface is defined by the exact subject and body strings in EmailService.
EmailService
src/main/java/com/bankasap/service/EmailService.java
Properties
| Property | Type | Description |
|---|---|---|
mailSender |
JavaMailSender |
Spring mail sender used to deliver every SimpleMailMessage created by the service. |
Constructor dependencies
| Type | Description |
|---|---|
JavaMailSender |
Injected into EmailService and assigned to mailSender. |
Public methods
| Method | Description |
|---|---|
sendTwoFactorCode |
Creates a mail message for the supplied recipient, sets the subject to Bank ASAP - 2FA Code, writes Your Bank ASAP authentication code is: plus the supplied code, and sends it through mailSender. |
sendAccountLockedEmail |
Creates a mail message for the supplied recipient, sets the subject to Bank ASAP - Account Locked, writes Your account was locked after 3 failed login attempts., and sends it through mailSender. |
Message templates
| Method | Subject | Body |
|---|---|---|
sendTwoFactorCode |
Bank ASAP - 2FA Code |
Your Bank ASAP authentication code is: + code |
sendAccountLockedEmail |
Bank ASAP - Account Locked |
Your account was locked after 3 failed login attempts. |
Mail dispatch behavior
- Each method creates a fresh
SimpleMailMessage. - Recipient, subject, and text are set before dispatch.
- Delivery happens immediately through
mailSender.send(message). - The service does not retain mail state between calls.
Java Mail Sender integration
JavaMailSender is the only infrastructure dependency directly injected into EmailService. The class treats it as a send-only transport and does not wrap it with retry, queueing, or message persistence in the provided source.
sequenceDiagram
actor User
participant C as AuthController
participant S as AuthService
participant E as EmailService
participant M as JavaMailSender
User->>C: signUp or login request
C->>S: signUp, resendSignUpCode, login, or resendCode
S->>E: sendTwoFactorCode
E->>M: send
Integration surface in AuthService
src/main/java/com/bankasap/service/AuthService.java
AuthService injects EmailService through its constructor and uses it as part of the authentication workflow. The same outbound mail path is reused for both sign-up verification and login verification codes.
Properties
| Property | Type | Description |
|---|---|---|
emailService |
EmailService |
Mail service used to send verification codes to users. |
passwordEncoder |
PasswordEncoder |
Used to hash sign-up passwords and verify login passwords. |
pendingSignUps |
List<PendingSignUp> |
In-memory collection of pending sign-up records that hold the hashed password, code, and expiry. |
userRepository |
UserRepository |
Repository used to read and persist User records. |
formatter |
DateTimeFormatter |
Formats lock-until timestamps in login responses. |
Public methods
| Method | Description |
|---|---|
signUp |
Validates the email and password, hashes the password, stores a PendingSignUp, and calls emailService.sendTwoFactorCode(email, code). |
verifySignUp |
Validates the pending sign-up code, creates a new User, saves it through userRepository, and removes the pending record. |
resendSignUpCode |
Replaces the pending sign-up code, extends its expiry, and calls emailService.sendTwoFactorCode(email, code). |
login |
Checks the stored password, tracks failed attempts, manages account locking, and calls emailService.sendTwoFactorCode(user.getEmail(), code) after a successful password match. |
verifyCode |
Validates the stored login verification code and clears it after successful verification. |
resendCode |
Reissues a login verification code for an unlocked user and calls emailService.sendTwoFactorCode(user.getEmail(), code). |
Email-triggering flows
| Method | Mail action | State updated before send |
|---|---|---|
signUp |
Sends a new sign-up verification code | Adds a new PendingSignUp with a 10-minute expiry |
resendSignUpCode |
Sends a replacement sign-up verification code | Updates the stored code and expiry on the existing PendingSignUp |
login |
Sends a login 2FA code | Clears failed attempts and lock state after successful password validation |
resendCode |
Sends a replacement login 2FA code | Refreshes the stored 2FA code and expiry for the User |
Integration surface in AuthController
[!NOTE]
EmailServicedefinessendAccountLockedEmail, but the observedAuthService.loginpath handles the third failed attempt by settinglockedUntiland returningAccount locked for 15 minuteswithout calling that method.
src/main/java/com/bankasap/controller/AuthController.java
AuthController is the HTTP entry point for the authentication flows that eventually reach EmailService. It does not send mail directly; it forwards request DTOs to AuthService, which then decides whether a verification email should be dispatched.
Properties
| Property | Type | Description |
|---|---|---|
authService |
AuthService |
Service used by every controller method in the class. |
Public methods
| Method | Description |
|---|---|
signUp |
Accepts SignUpRequest, calls authService.signUp, and returns AuthResponse. |
verifySignUp |
Accepts VerifySignUpRequest, calls authService.verifySignUp, and returns AuthResponse. |
resendSignUpCode |
Accepts ResendSignUpCodeRequest, calls authService.resendSignUpCode, and returns AuthResponse. |
login |
Accepts LoginRequest, calls authService.login, and returns AuthResponse. |
verifyCode |
Accepts VerifyCodeRequest, calls authService.verifyCode, and returns AuthResponse. |
resendCode |
Accepts ResendCodeRequest, calls authService.resendCode, and returns AuthResponse. |
Controller-to-service request path
signUpforwardsSignUpRequest.email,SignUpRequest.password, andSignUpRequest.confirmPassword.verifySignUpforwardsVerifySignUpRequest.emailandVerifySignUpRequest.code.resendSignUpCodeforwardsResendSignUpCodeRequest.email.loginforwardsLoginRequest.emailandLoginRequest.password.verifyCodeforwardsVerifyCodeRequest.emailandVerifyCodeRequest.code.resendCodeforwardsResendCodeRequest.email.
HTTP integration points
Signup
Signup
{
"title": "Signup",
"description": "Creates a pending sign-up record and sends a verification code by email.",
"method": "POST",
"baseUrl": "<ServiceBaseUrl>",
"endpoint": "/signup",
"headers": [
{
"key": "Content-Type",
"value": "application/json",
"required": true
}
],
"queryParams": [],
"pathParams": [],
"bodyType": "json",
"requestBody": "{\n \"email\": \"[email protected]\",\n \"password\": \"SecurePass1!\",\n \"confirmPassword\": \"SecurePass1!\"\n}",
"formData": [],
"rawBody": "",
"responses": {
"200": {
"description": "Success",
"body": "{\n \"message\": \"Signup verification code sent to email\"\n}"
}
}
}
Verify Signup
{
"title": "Verify Signup",
"description": "Confirms the sign-up verification code and persists the new user.",
"method": "POST",
"baseUrl": "<ServiceBaseUrl>",
"endpoint": "/verify-signup",
"headers": [
{
"key": "Content-Type",
"value": "application/json",
"required": true
}
],
"queryParams": [],
"pathParams": [],
"bodyType": "json",
"requestBody": "{\n \"email\": \"[email protected]\",\n \"code\": \"AB12CD34EF\"\n}",
"formData": [],
"rawBody": "",
"responses": {
"200": {
"description": "Success",
"body": "{\n \"message\": \"User registered successfully\"\n}"
}
}
}
Resend Signup Code
{
"title": "Resend Signup Code",
"description": "Generates a fresh sign-up verification code and emails it to the pending user.",
"method": "POST",
"baseUrl": "<ServiceBaseUrl>",
"endpoint": "/resend-signup-code",
"headers": [
{
"key": "Content-Type",
"value": "application/json",
"required": true
}
],
"queryParams": [],
"pathParams": [],
"bodyType": "json",
"requestBody": "{\n \"email\": \"[email protected]\"\n}",
"formData": [],
"rawBody": "",
"responses": {
"200": {
"description": "Success",
"body": "{\n \"message\": \"New signup verification code sent to email\"\n}"
}
}
}
Login
Login
{
"title": "Login",
"description": "Validates credentials, updates lock and attempt state, and sends a login 2FA code by email after password verification succeeds.",
"method": "POST",
"baseUrl": "<ServiceBaseUrl>",
"endpoint": "/login",
"headers": [
{
"key": "Content-Type",
"value": "application/json",
"required": true
}
],
"queryParams": [],
"pathParams": [],
"bodyType": "json",
"requestBody": "{\n \"email\": \"[email protected]\",\n \"password\": \"SecurePass1!\"\n}",
"formData": [],
"rawBody": "",
"responses": {
"200": {
"description": "Success",
"body": "{\n \"message\": \"2FA code sent to email\"\n}"
}
}
}
Verify Code
{
"title": "Verify Code",
"description": "Checks the login verification code stored on the user record and clears it after a successful match.",
"method": "POST",
"baseUrl": "<ServiceBaseUrl>",
"endpoint": "/verify-code",
"headers": [
{
"key": "Content-Type",
"value": "application/json",
"required": true
}
],
"queryParams": [],
"pathParams": [],
"bodyType": "json",
"requestBody": "{\n \"email\": \"[email protected]\",\n \"code\": \"AB12CD34EF\"\n}",
"formData": [],
"rawBody": "",
"responses": {
"200": {
"description": "Success",
"body": "{\n \"message\": \"Login successful\"\n}"
}
}
}
Resend Login Code
{
"title": "Resend Login Code",
"description": "Reissues a login 2FA code for an unlocked user and emails the new code.",
"method": "POST",
"baseUrl": "<ServiceBaseUrl>",
"endpoint": "/resend-login-code",
"headers": [
{
"key": "Content-Type",
"value": "application/json",
"required": true
}
],
"queryParams": [],
"pathParams": [],
"bodyType": "json",
"requestBody": "{\n \"email\": \"[email protected]\"\n}",
"formData": [],
"rawBody": "",
"responses": {
"200": {
"description": "Success",
"body": "{\n \"message\": \"New 2FA code sent to email\"\n}"
}
}
}