-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from correctexam/develop
sendEmail with RaplyTo
- Loading branch information
Showing
2 changed files
with
41 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -483,6 +483,21 @@ public Response sendResultToStudent(MailResultDTO dto, @PathParam("examId") long | |
if (!securityService.canAccess(ctx, examId, Exam.class)) { | ||
return Response.status(403, "Current user cannot access to this ressource").build(); | ||
} | ||
|
||
var userLogin = Optional | ||
.ofNullable(ctx.getUserPrincipal().getName()); | ||
if (!userLogin.isPresent()){ | ||
throw new AccountResourceException("Current user login not found"); | ||
} | ||
var user = User.findOneByLogin(userLogin.get()); | ||
if (!user.isPresent()) { | ||
throw new AccountResourceException("User could not be found"); | ||
} | ||
String _replyTo = user.get().email; | ||
if (_replyTo == null || "".equals(_replyTo)){ | ||
_replyTo= "[email protected]"; | ||
} | ||
final String replyTo = _replyTo; | ||
Exam ex = this.computeFinalNote(examId); | ||
|
||
List<Student> students = Student.findStudentsbyCourseId(ex.course.id).list(); | ||
|
@@ -492,6 +507,7 @@ public Response sendResultToStudent(MailResultDTO dto, @PathParam("examId") long | |
FinalResult r = FinalResult.findFinalResultByStudentIdAndExamId(student.id, ex.id).firstResult(); | ||
ExamSheet sheet = ExamSheet.findExamSheetByScanAndStudentId(ex.scanfile.id, student.id).firstResult(); | ||
String uuid = sheet.name; | ||
|
||
String body = dto.getBody(); | ||
body = body.replace("${url}", this.jHipsterProperties.mail().baseUrl() + "/copie/" + uuid + "/1"); | ||
body = body.replace("${firstname}", student.firstname); | ||
|
@@ -504,20 +520,20 @@ public Response sendResultToStudent(MailResultDTO dto, @PathParam("examId") long | |
in = this.cacheStudentPdfFService.getFile(examId, sheet.name + ".pdf"); | ||
byte[] bytes = IOUtils.toByteArray(in); | ||
mailService.sendEmailWithAttachement(student.mail, body, dto.getSubject(), | ||
student.firstname + "_" + student.name + ".pdf", bytes, "application/pdf"); | ||
student.firstname + "_" + student.name + ".pdf", bytes, "application/pdf",replyTo); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} else { | ||
mailService.sendEmail(student.mail, body, dto.getSubject()); | ||
mailService.sendEmail(student.mail, body, dto.getSubject(),replyTo); | ||
} | ||
|
||
} else { | ||
if (dto.isMailabi()) { | ||
String body = dto.getBodyabi(); | ||
body = body.replace("${firstname}", student.firstname); | ||
body = body.replace("${lastname}", student.name); | ||
mailService.sendEmail(student.mail, body, dto.getSubject()); | ||
mailService.sendEmail(student.mail, body, dto.getSubject(),replyTo); | ||
} | ||
} | ||
}); | ||
|