EmailSender { protected void sendHtmlEmail(String subject, String htmlMessage, String textMessage, String toEmailAddress, Map<File, ImageType> attachments) throws MailException { if ( !emailConfig.isEmailEnabled() ) { logger.info("Email sending is not enabled!"); return; } MultiPartEmail email = createEmail(subject, htmlMessage, textMessage); try { email.addTo(toEmailAddress); } catch ( EmailException ex ) { logger.error("Invalid 'to' (" + toEmailAddress + ") address", ex); throw new MailException(MailException.INVALID_TO_ADDRESS, ex); } if ( attachments != null && !attachments.isEmpty() ) { for ( Map.Entry<File, ImageType> entry : attachments.entrySet() ) { File attachment = entry.getKey(); ImageType imageType = entry.getValue(); if ( attachment == null || !attachment.isFile() || !attachment.exists() || attachment.length() == 0 ) { logger.debug("Skipping file attachment as is not as expected (attachment: " + attachment + ")"); continue; } try { String name = attachment.getName() + (imageType != null ? "." + imageType.getFormatName() : ""); email.attach(new FileDataSource(attachment), name, null); } catch ( EmailException ex ) { logger.error("Cannot attach file (name: " + attachment.getName() + ")", ex); } } } try { email.send(); } catch ( EmailException ex ) { logger.error("Cannot send email", ex); throw new MailException(MailException.EMAIL_SEND_ERROR, ex); } }  @PostConstruct void init(); boolean sendNotification(NotificationType notificationType, User user, Map<String, Object> vars); boolean sendNotification(NotificationType notificationType, User user, Map<String, Object> vars, Map<File, ImageType> attachments); boolean sendNotification(NotificationType notificationType, String subtype, User user, Map<String, Object> vars); boolean sendNotification(NotificationType notificationType, String subtype, User user, Map<String, Object> vars, Map<File, ImageType> attachments); boolean sendNotification(NotificationType notificationType, String email, Map<String, Object> vars); boolean sendNotification(NotificationType notificationType, String email, Map<String, Object> vars, Map<File, ImageType> attachments); boolean sendNotification(NotificationType notificationType, String subtype, String email, Map<String, Object> vars); boolean sendNotification(NotificationType notificationType, String subtype, String email, Map<String, Object> vars, Map<File, ImageType> attachments);  }
@Test @Ignore public void sendHtmlEmailTest() throws MailException { emailSender.sendHtmlEmail("Mail subject", "HTML message", "PLAIN message", "venefica.labs@yatko.com", null); }