optimized mails

This commit is contained in:
Jottyfan 2022-12-17 18:01:46 +01:00
parent 028c4d4fd4
commit be0859b93f
6 changed files with 182 additions and 145 deletions

View File

@ -203,22 +203,27 @@ public class PersonGateway {
String campNameWithYear = lrw.getString("campNameWithYear"); String campNameWithYear = lrw.getString("campNameWithYear");
String email = lrw.getString("oldEmail"); String email = lrw.getString("oldEmail");
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
String subject = "allgemeine Nachricht vom Buchungsportal der Onkel-Werner-Freizeiten";
Boolean sendMail = false;
if (acceptNew == null) { if (acceptNew == null) {
if (acceptOld != null) { if (acceptOld != null) {
subject = new StringBuilder("Deine Teilnahme an ").append(campNameWithYear).append(" wurde zurückgesetzt")
.toString();
buf = new StringBuilder("Die Bestätigung der Anmeldung von "); buf = new StringBuilder("Die Bestätigung der Anmeldung von ");
buf.append(bean.getForename()); buf.append(bean.getForename());
buf.append(" "); buf.append(" ");
buf.append(bean.getSurname()); buf.append(bean.getSurname());
buf.append(" zur Freizeit "); buf.append(" zur Freizeit ");
buf.append(campNameWithYear); buf.append(campNameWithYear);
buf.append(" wurde von "); buf.append(" wurde wieder zurückgezogen.");
buf.append(registrator);
buf.append(" wieder zurückgezogen.");
buf.append( buf.append(
" Möglicherweise wurde die Anmeldung versehentlich bestätigt? Deine Anmeldung befindet sich jetzt wieder auf der Warteliste."); " Möglicherweise wurde die Anmeldung versehentlich bestätigt? Deine Anmeldung befindet sich jetzt wieder auf der Warteliste.");
sendMail = true;
} }
} else if (acceptNew == true) { } else if (acceptNew == true) {
if (acceptOld == null || !acceptOld) { if (acceptOld == null || !acceptOld) {
subject = new StringBuilder("Deine Teilnahme an ").append(campNameWithYear).append(" wurde bestätigt")
.toString();
buf = new StringBuilder("Die Anmeldung von "); buf = new StringBuilder("Die Anmeldung von ");
buf.append(bean.getForename()); buf.append(bean.getForename());
buf.append(" "); buf.append(" ");
@ -226,10 +231,13 @@ public class PersonGateway {
buf.append(" zur Freizeit "); buf.append(" zur Freizeit ");
buf.append(campNameWithYear); buf.append(campNameWithYear);
buf.append(" wurde bestätigt. Melde Dich jetzt unter https://www.onkelwernerfreizeiten.de/camporganizer an,"); buf.append(" wurde bestätigt. Melde Dich jetzt unter https://www.onkelwernerfreizeiten.de/camporganizer an,");
buf.append(" um die Bestätigungen herunterzuladen."); buf.append(" um die zu unterschreibenden Dokumente herunterzuladen, auszudrucken und uns zukommen zu lassen.");
sendMail = true;
} }
} else if (acceptNew == false) { } else if (acceptNew == false) {
if (acceptOld == null || acceptOld) { if (acceptOld == null || acceptOld) {
subject = new StringBuilder("Deine Teilnahme an ").append(campNameWithYear).append(" wurde abgelehnt")
.toString();
buf = new StringBuilder("Die Anmeldung von "); buf = new StringBuilder("Die Anmeldung von ");
buf.append(bean.getForename()); buf.append(bean.getForename());
buf.append(" "); buf.append(" ");
@ -239,16 +247,19 @@ public class PersonGateway {
buf.append(" wurde leider abgelehnt."); buf.append(" wurde leider abgelehnt.");
buf.append( buf.append(
" Möglicherweise ist sie schon ausgebucht? Deine Anmeldung befindet sich jetzt auf der Nachrückerliste."); " Möglicherweise ist sie schon ausgebucht? Deine Anmeldung befindet sich jetzt auf der Nachrückerliste.");
sendMail = true;
} }
} }
if (sendMail) {
Set<String> to = new HashSet<>(); Set<String> to = new HashSet<>();
to.add(email); to.add(email);
to.add(bean.getEmail()); to.add(bean.getEmail());
try { try {
mailRepository.sendMail(to, buf.toString()); // no matter if the sending works, do the persistence anyway mailRepository.sendMail(to, subject, buf.toString()); // no matter if the sending works
} catch (Exception e) { } catch (Exception e) {
LOGGER.error(e.getMessage(), e); LOGGER.error(e.getMessage(), e);
} }
}
return lrw.getCounter(); return lrw.getCounter();
} }

View File

@ -35,13 +35,14 @@ public class MailRepository {
* nothing * nothing
* *
* @param to the email addresses * @param to the email addresses
* @param subject the subject
* @param message the message * @param message the message
*/ */
public void sendMail(Set<String> to, String message) { public void sendMail(Set<String> to, String subject, String message) {
if (to != null && to.size() > 0) { if (to != null && to.size() > 0) {
if (username != null && !username.isBlank()) { if (username != null && !username.isBlank()) {
try { try {
sendMail(to, message, username); sendMail(to, subject, message, username);
} catch (MessagingException e) { } catch (MessagingException e) {
LOGGER.error(e.getMessage(), e); LOGGER.error(e.getMessage(), e);
} }
@ -58,11 +59,12 @@ public class MailRepository {
* send the email * send the email
* *
* @param to the recipients * @param to the recipients
* @param subject the subject
* @param message the message * @param message the message
* @param from the username of the email account * @param from the username of the email account
* @throws MessagingException * @throws MessagingException
*/ */
private void sendMail(Set<String> to, String message, String from) throws MessagingException { private void sendMail(Set<String> to, String subject, String message, String from) throws MessagingException {
if (to == null || to.size() < 1) { if (to == null || to.size() < 1) {
throw new MessagingException("no recipient in " + to); throw new MessagingException("no recipient in " + to);
} }
@ -70,7 +72,7 @@ public class MailRepository {
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED, MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED,
StandardCharsets.UTF_8.name()); StandardCharsets.UTF_8.name());
helper.setFrom(from); helper.setFrom(from);
helper.setSubject("Information zu Deiner Anmeldung zur Onkel Werner Freizeit"); helper.setSubject(subject);
helper.setText(message, false); helper.setText(message, false);
helper.setTo(to.toArray(new String[] {})); helper.setTo(to.toArray(new String[] {}));
javaMailSender.send(mimeMessage); javaMailSender.send(mimeMessage);

View File

@ -333,3 +333,17 @@ div {
.mytoggle_btn:hover { .mytoggle_btn:hover {
background-color: #abcdef; background-color: #abcdef;
} }
.loading {
position: absolute;
background: rgba(0, 0, 0, 0.5);
color: white;
font-weight: bolder;
font-size: xx-large;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
text-align: center;
padding-top: 45vh;
}

View File

@ -0,0 +1,9 @@
progress = {
start : function(zin) {
zin = zin || 1000;
$("body").append("<div id=\"requestopen\" class=\"loading\" style=\"z-index: " + zin + " !important\"><i class=\"fa fa-spinner fa-pulse\"></i></div>");
},
stop : function() {
$("#requestopen").remove();
}
}

View File

@ -125,7 +125,7 @@
<div class="row mb-2"> <div class="row mb-2">
<label for="inputAccept" class="col-sm-2 col-form-label"></label> <label for="inputAccept" class="col-sm-2 col-form-label"></label>
<div class="col-sm-10"> <div class="col-sm-10">
<button type="submit" class="btn btn-primary">Ok</button> <button type="submit" class="btn btn-primary" onclick="progress.start()">Ok</button>
<a th:href="@{/confirmation/}" class="btn btn-secondary">Abbrechen</a> <a th:href="@{/confirmation/}" class="btn btn-secondary">Abbrechen</a>
</div> </div>
</div> </div>

View File

@ -16,6 +16,7 @@
<script th:src="@{/js/dataTables.de.js}"></script> <script th:src="@{/js/dataTables.de.js}"></script>
<script th:src="@{/js/mytoggle.js}"></script> <script th:src="@{/js/mytoggle.js}"></script>
<script th:src="@{/js/myAjax.js}"></script> <script th:src="@{/js/myAjax.js}"></script>
<script th:src="@{/js/progress.js}"></script>
<th:block layout:fragment="libs"></th:block> <th:block layout:fragment="libs"></th:block>
</head> </head>
<body> <body>