@CrossOrigin(origins = "*") @RequestMapping(value = "/sendEmailFromTo") @ResponseStatus(HttpStatus.OK) public String sendEmail(String fromAddress, String toAddress, String uuid) throws IOException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); Message message = new Message( fromAddress, toAddress, "Your mazda routes exported at " + sdf.format(new Date()), "These are your exported cached routes from Mazda"); byte[] data = createZip(uuid); Attachment attachment = new Attachment("routes.zip", data); message.setAttachments(attachment); try { mailService.send(message); log.info("Routes sent to \"{}\"", toAddress); } catch (CallNotFoundException ex) { log.error("Cannot send email: {}", ExceptionUtils.getRootCauseMessage(ex)); File file = new File("routes_" + toAddress + "_" + System.currentTimeMillis() + ".zip"); FileUtils.writeByteArrayToFile(file, data); log.info("Routes save to file: {}", file.getAbsolutePath()); } finally { routeRepository.clearRoutes(uuid); } return "{}"; }