Fakultas Ilmu Komputer UI
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
be-authentication-test
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SafetyPin
be-authentication-test
Commits
8ab4725d
Commit
8ab4725d
authored
2 months ago
by
Darrel Danadyaksa Poli
Browse files
Options
Downloads
Patches
Plain Diff
[REFACTOR] Update EmailService to send OTP emails asynchronously using CompletableFuture
parent
08226c49
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/com/safetypin/authentication/service/EmailService.java
+7
-3
7 additions, 3 deletions
...va/com/safetypin/authentication/service/EmailService.java
with
7 additions
and
3 deletions
src/main/java/com/safetypin/authentication/service/EmailService.java
+
7
−
3
View file @
8ab4725d
...
@@ -6,8 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -6,8 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.mail.MailException
;
import
org.springframework.mail.MailException
;
import
org.springframework.mail.SimpleMailMessage
;
import
org.springframework.mail.SimpleMailMessage
;
import
org.springframework.mail.javamail.JavaMailSender
;
import
org.springframework.mail.javamail.JavaMailSender
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.concurrent.CompletableFuture
;
@Service
@Service
public
class
EmailService
{
public
class
EmailService
{
private
final
JavaMailSender
mailSender
;
private
final
JavaMailSender
mailSender
;
...
@@ -20,7 +23,8 @@ public class EmailService {
...
@@ -20,7 +23,8 @@ public class EmailService {
this
.
mailSender
=
mailSender
;
this
.
mailSender
=
mailSender
;
}
}
public
boolean
sendOTPMail
(
String
to
,
String
otp
)
{
@Async
(
"emailTaskExecutor"
)
public
CompletableFuture
<
Boolean
>
sendOTPMail
(
String
to
,
String
otp
)
{
SimpleMailMessage
message
=
new
SimpleMailMessage
();
SimpleMailMessage
message
=
new
SimpleMailMessage
();
message
.
setFrom
(
SENDER
);
message
.
setFrom
(
SENDER
);
message
.
setTo
(
to
);
message
.
setTo
(
to
);
...
@@ -29,10 +33,10 @@ public class EmailService {
...
@@ -29,10 +33,10 @@ public class EmailService {
try
{
try
{
mailSender
.
send
(
message
);
mailSender
.
send
(
message
);
return
CompletableFuture
.
completedFuture
(
true
);
}
catch
(
MailException
e
)
{
}
catch
(
MailException
e
)
{
logger
.
warn
(
"EmailService.sendOTPMail:: Failed to send mail with error; {}"
,
e
.
getMessage
());
logger
.
warn
(
"EmailService.sendOTPMail:: Failed to send mail with error; {}"
,
e
.
getMessage
());
return
false
;
return
CompletableFuture
.
completedFuture
(
false
)
;
}
}
return
true
;
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment