|
10 | 10 | import org.mskcc.cbio.oncokb.domain.Company;
|
11 | 11 | import org.mskcc.cbio.oncokb.domain.UserMessagePair;
|
12 | 12 | import org.mskcc.cbio.oncokb.domain.enumeration.MailType;
|
| 13 | +import org.mskcc.cbio.oncokb.service.dto.TerminationEmailDTO; |
13 | 14 | import org.mskcc.cbio.oncokb.service.dto.UserDTO;
|
14 | 15 | import org.mskcc.cbio.oncokb.service.dto.UserMailsDTO;
|
15 | 16 | import org.mskcc.cbio.oncokb.web.rest.vm.ExposedToken;
|
@@ -85,6 +86,20 @@ private UnknownMailTypeException() {
|
85 | 86 | }
|
86 | 87 | }
|
87 | 88 |
|
| 89 | + public void sendEmail(TerminationEmailDTO dto) throws MessagingException { |
| 90 | + log.debug("Send email to company ID '{}' with subject '{}' and content={}", |
| 91 | + dto.getCompanyId(), dto.getSubject(), dto.getContent()); |
| 92 | + |
| 93 | + MimeMessage mimeMessage = javaMailSender.createMimeMessage(); |
| 94 | + MimeMessageHelper message = new MimeMessageHelper(mimeMessage, false, StandardCharsets.UTF_8.name()); |
| 95 | + message.setFrom(dto.getFrom()); |
| 96 | + message.setBcc(dto.getBcc().split(";")); |
| 97 | + message.setCc(dto.getCc().split(";")); |
| 98 | + message.setSubject(dto.getSubject()); |
| 99 | + message.setText(dto.getContent(), false); |
| 100 | + javaMailSender.send(mimeMessage); |
| 101 | + } |
| 102 | + |
88 | 103 | @Async
|
89 | 104 | public void sendEmail(String to, String from, String cc, String subject, String content, List<String> attachmentFilesNames, boolean isMultipart, boolean isHtml) throws MessagingException {
|
90 | 105 | log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
|
@@ -236,6 +251,21 @@ public void sendEmailFromTemplate(UserDTO user, MailType mailType, String subjec
|
236 | 251 | }
|
237 | 252 | }
|
238 | 253 |
|
| 254 | + public void sendInternalEmailFromTemplate(MailType mailType, String subject, String to, Context additionalContext) { |
| 255 | + Context context = new Context(Locale.ENGLISH); |
| 256 | + |
| 257 | + if (additionalContext != null) |
| 258 | + additionalContext.getVariableNames().forEach(name -> context.setVariable(name, additionalContext.getVariable(name))); |
| 259 | + |
| 260 | + String from = jHipsterProperties.getMail().getFrom(); |
| 261 | + String content = templateEngine.process("mail/" + mailType.getTemplateName(), context); |
| 262 | + try { |
| 263 | + sendEmail(to, from, null, subject, content, null, false, true); |
| 264 | + } catch (MailException | MessagingException e) { |
| 265 | + log.warn("Internal email could not be sent to '{}'", to, e); |
| 266 | + } |
| 267 | + } |
| 268 | + |
239 | 269 | @Async
|
240 | 270 | public void sendActivationEmail(UserDTO user) {
|
241 | 271 | log.debug("Sending activation email to '{}'", user.getEmail());
|
|
0 commit comments