Skip to content

Commit

Permalink
Merge pull request #208 from Jona511/birthdayListPlugin
Browse files Browse the repository at this point in the history
Add HTML mail template to birthday butler
  • Loading branch information
kreinhard authored Sep 27, 2023
2 parents a645600 + 618f7c0 commit c2eaea1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import org.projectforge.mail.Mail
import org.projectforge.mail.MailAttachment
import org.projectforge.mail.SendMail
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ApplicationContext
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Service
import java.io.IOException
Expand All @@ -62,9 +61,6 @@ class BirthdayButlerService {
@Autowired
private lateinit var addressDao: AddressDao

@Autowired
private lateinit var applicationContext: ApplicationContext

@Autowired
private lateinit var birthdayButlerConfiguration: BirthdayButlerConfiguration

Expand Down Expand Up @@ -95,7 +91,8 @@ class BirthdayButlerService {
val response = createWord(month, locale)
val error = response.errorMessage
if (error != null) {
log.error { "BirthdayButlerJob aborted: ${translate(error)}" }
log.error { "BirthdayButlerJob aborted: ${translate(error)} + $error" }
sendMail(month, content = error, locale = locale)
return
}
val word = response.wordDocument
Expand All @@ -113,7 +110,7 @@ class BirthdayButlerService {
list.add(attachment)
sendMail(month, content = "birthdayButler.email.content", mailAttachments = list, locale = locale)
} else {
sendMail(month, content = "birthdayButler.email.content.noBirthdaysFound", locale = locale)
sendMail(month, content = "birthdayButler.wordDocument.error", locale = locale)
}
log.info("BirthdayButlerJob finished.")
}
Expand Down Expand Up @@ -152,21 +149,39 @@ class BirthdayButlerService {

}

private fun sendMail(month: Month, content: String, mailAttachments: List<MailAttachment>? = null, locale: Locale?) {
private fun sendMail(
month: Month,
content: String,
mailAttachments: List<MailAttachment>? = null,
locale: Locale?
) {
val emails = getEMailAddressesFromConfig()
if (!emails.isNullOrEmpty()) {
val subject = "${translate(locale, "birthdayButler.email.subject")} ${translateMonth(month, locale)}"
val mail = Mail()
mail.subject = subject
mail.contentType = Mail.CONTENTTYPE_HTML
emails.forEach { address ->
val mail = Mail()
mail.subject = subject
mail.contentType = Mail.CONTENTTYPE_HTML
mail.setTo(address)
mail.content = translate(content)
//mail.content = translate(content)

val data = mutableMapOf<String, Any?>(
"content" to content,
"month" to translateMonth(month, locale),
"listSize" to getBirthdayList(month)?.size
)
mail.content = sendMail.renderGroovyTemplate(
mail,
"mail/birthdayButlerCronMail.html",
data,
title = subject,
recipient = null
)
try {
sendMail.send(mail, attachments = mailAttachments)
log.info { "Send mail to $address" }
} catch (ex: Exception) {
log.error("error while trying to send mail to '$address': ${ex.message}", ex)
log.error("Error while trying to send mail to '$address': ${ex.message}", ex)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2673,8 +2673,9 @@ attr.starttime.alreadyexists.day=There is already an entry with the same date (D
attr.starttime.alreadyexists.month=There is already an entry with the same date (Month).
attr.validFrom=Valid from

birthdayButler.email.content=Attached is the list of upcoming birthdays for the next month.<br /> This E-Mail is automatically generated by ProjectForge.
birthdayButler.email.content.noBirthdaysFound=No birthdays found for this month.<br />This E-Mail is automatically generated by ProjectForge.
birthdayButler.email.opening=New month, new birthday list!
birthdayButler.email.content=In the month of {0}, {1} employees are celebrating their birthdays. Attached, you will find the list of birthdays.
birthdayButler.email.content.noBirthdaysFound=No birthday entries were found in the month of {0}.
birthdayButler.email.subject=Birthday list for
birthdayButler.month.response.noEntry=There are no birthday entries for this month.
birthdayButler.month.response.nothingSelected=The month is required.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2770,8 +2770,9 @@ attr.starttime.alreadyexists.day=Es existiert bereits ein Eintrag mit gleichem D
attr.starttime.alreadyexists.month=Es existiert bereits ein Eintrag mit gleichem Datum (Monat).
attr.validFrom=Gültig ab

birthdayButler.email.content=Anbei die Liste der Geburtstage für den nächsten Monat.<br /> Diese E-Mail wurde automatisch von ProjectForge generiert.
birthdayButler.email.content.noBirthdaysFound=No birthdays found for this month.<br />This E-Mail is automatically generated by ProjectForge.
birthdayButler.email.opening=Ein neuer Monat, eine neue Geburtstagsliste!
birthdayButler.email.content=Im Monat {0} haben {1} Mitarbeiter Geburtstag. Im Anhang findest du die Liste der Geburtstage.
birthdayButler.email.content.noBirthdaysFound=Im Monat {0} wurden keine Geburtstagseinträge gefunden.
birthdayButler.email.subject=Geburtstagsliste für
birthdayButler.month.response.noEntry=Es gibt keine Geburtstagseinträge für diesen Monat.
birthdayButler.month.response.nothingSelected=Der Monat muss ausgewählt sein.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<html>
#INCLUDE{mail/mailHead.html}
<body>
<div id="mail">
<div class="container">
<div class="content">
<!--Header without the address-->
<% if (pf.isVariableGiven("logoUrl")) { %>
<a href="<%= pf.getString(baseUrl) %>" target="_blank" rel="noreferrer">
<img src="<%= pf.getString(logoUrl) %>" class="logo" alt="Logo">
</a> <% } %>
<h1 class="title"><%= pf.getString(title) %></h1>

<p><%= pf.getMessage("birthdayButler.email.opening") %></p>
<br>
<p>
<%= pf.getMessage(content, "<b>${month}</b>", "<b>${listSize}</b>") %>
</p>
<br>
#INCLUDE{mail/mailClosing.html}
#INCLUDE{mail/mailFooter.html}
</div>
</div>
</div>
</body>
</html>

0 comments on commit c2eaea1

Please sign in to comment.