package de.predic8.routes;

import de.predic8.Archive;
import de.predic8.util.EmailNewFiles;
import de.predic8.util.PropertyFile;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

public class DailyMailNotification extends RouteBuilder {

    public void configure() throws Exception {

        from("file:document-archive/notify?fileName=new_files.txt&noop=true").routeId("DailyNotify")
                .log("SENDING EMAIL")
                .setHeader("subject", simple("Daily Report"))
                .setHeader("firstName", simple(PropertyFile.getInstance().getProperty("user_name")))
                .process(new EmailNewFiles())
                .to("freemarker:/email-templates/daily_report.ftl")
                .to(String.format("smtp://%s?password=%s&username=%s&to=%s&from=%s"
                        , PropertyFile.getInstance().getProperty("email_smtp")
                        , PropertyFile.getInstance().getProperty("email_password")
                        , PropertyFile.getInstance().getProperty("email_username")
                        , PropertyFile.getInstance().getProperty("email_recipient")
                        , PropertyFile.getInstance().getProperty("email_username")))
                .log("EMAIL SEND");

    }

    public void start() throws Exception {
        CamelContext ctx = new DefaultCamelContext();
        ctx.addRoutes(new DailyMailNotification());
        ctx.start();
        Thread.sleep(5000);
    }
}

@@ -48,16 +48,54 @@
 rchive;%0A
+import de.predic8.util.AttachLogfile;%0A
 import d
@@ -199,16 +199,84 @@
 ontext;%0A
+import org.apache.camel.Endpoint;%0Aimport org.apache.camel.Exchange;%0A
 import o
@@ -483,248 +483,152 @@
     
-from(%22file:document-archive/notify?fileName=new_files.txt&noop=true%22).routeId(%22DailyNotify%22)%0A                .log(%22SENDING EMAIL%22)%0A                .setHeader(%22subject%22, simple(%22Daily Report%22))%0A                .setHeader(%22firstName%22, simple(
+Endpoint smtp = getContext().getEndpoint(%0A                String.format(%22smtp://%25s?password=%25s&username=%25s&to=%25s&from=%25s%22%0A                    , 
 Prop
@@ -667,20 +667,19 @@
 ty(%22
-user_name%22))
+email_smtp%22
 )%0A  
@@ -696,194 +696,71 @@
     
-.process(new EmailNewFiles())%0A                .to(%22freemarker:/email-templates/daily_report.ftl%22)%0A                .to(String.format(%22smtp://%25s?password=%25s&username=%25s&to=%25s&from=%25s%22%0A    
+    , PropertyFile.getInstance().getProperty(%22email_password%22)%0A
     
@@ -819,35 +819,35 @@
 erty(%22email_
-smtp%22)%0A    
+username%22)%0A
             
@@ -898,39 +898,36 @@
 erty(%22email_
-password%22)%0A    
+recipient%22)%0A
             
@@ -984,32 +984,36 @@
 email_username%22)
+));%0A
 %0A               
@@ -1005,34 +1005,256 @@
         
-                , 
+from(%22file:document-archive/notify?fileName=new_files.txt&noop=true%22).routeId(%22DailyNotify%22)%0A                .log(%22SENDING EMAIL%22)%0A                .setHeader(%22subject%22, simple(%22Daily Report%22))%0A                .setHeader(%22firstName%22, simple(
 Property
@@ -1285,32 +1285,28 @@
 operty(%22
-email_recipient%22
+user_name%22))
 )%0A      
@@ -1319,75 +1319,176 @@
     
-        , PropertyFile.getInstance().getProperty(%22email_username%22))
+.process(new EmailNewFiles())%0A                .to(%22freemarker:/email-templates/daily_report.ftl%22)%0A                .process(new AttachLogfile())%0A                .to(smtp
 )%0A  

send log.txt as attachment