@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 "{}";
 }
Exemplo n.º 2
0
 private void sendMail(
     HttpServletRequest request, BlogAuthor blogAuthor, Entity blog, Settings settings)
     throws IOException {
   if (settings.dontSendEmail()) {
     return;
   }
   try {
     String digest = DS.getBlogDigest(blog);
     MailService mailService = MailServiceFactory.getMailService();
     Message reply = new Message();
     reply.setSender(blogAuthor.toString());
     Email sender = (Email) blog.getProperty(SenderProperty);
     reply.setTo(sender.getEmail());
     String subject = (String) blog.getProperty(SubjectProperty);
     reply.setSubject("Blog: " + subject + " received");
     StringBuilder sb = new StringBuilder();
     URI reqUri = new URI(request.getScheme(), NamespaceManager.get(), "", "");
     if (!settings.isPublishImmediately()) {
       sb.append("<div>");
       sb.append(
           "<p>Blog is not yet published because it was sent from untrusted email address "
               + sender.getEmail()
               + ". </p>");
       URI publishUri =
           reqUri.resolve(
               "/blog?action=publish&blog="
                   + KeyFactory.keyToString(blog.getKey())
                   + "&auth="
                   + digest);
       sb.append("<a href=\"" + publishUri.toASCIIString() + "\">Publish Blog</a>");
       sb.append("</div>");
     }
     sb.append("<div>");
     sb.append("<p>If blog is not ok, you can delete and then resend it.</p>");
     URI deleteUri =
         reqUri.resolve(
             "/blog?action=remove&blog="
                 + KeyFactory.keyToString(blog.getKey())
                 + "&auth="
                 + digest);
     sb.append("<a href=\"" + deleteUri.toASCIIString() + "\">Delete Blog</a>");
     sb.append("</div>");
     reply.setHtmlBody(sb.toString());
     mailService.send(reply);
   } catch (URISyntaxException ex) {
     throw new IOException(ex);
   }
 }