Skip to content

Instantly share code, notes, and snippets.

@damc-dev
Created January 16, 2017 18:28
Show Gist options
  • Save damc-dev/dddb15ae462a6de2d613bf6a453f1671 to your computer and use it in GitHub Desktop.
Save damc-dev/dddb15ae462a6de2d613bf6a453f1671 to your computer and use it in GitHub Desktop.
Poll Email with Groovy and Apache Camel
#!/usr/bin/env groovy
import org.apache.camel.impl.DefaultCamelContext
import org.apache.camel.builder.*
@Grab(group='org.apache.camel', module='camel-groovy', version='2.11.0')
@Grab(group='org.apache.camel', module='camel-mail', version='2.11.0')
@Grab(group='org.apache.camel', module='camel-core', version='2.11.0')
@Grab(group='org.slf4j', module='slf4j-log4j12', version='1.7.5')
def email = '[email protected]'
def password = 'fakeGmailPassowrdToken'
def emailRoute = new RouteBuilder() {
def void configure() {
from("imaps://imap.gmail.com?username=${email}"
+ "&password=${password}"
+ "&debugMode=true"
+ "&delete=false"
+ "&unseen=true"
+ "&consumer.delay=10000")
.to("log:newmail")
}
}
def camelCtx = new DefaultCamelContext()
camelCtx.addRoutes(emailRoute);
camelCtx.start();
addShutdownHook{
println "Shutting down...."
camelCtx.stop()
}
Scanner s=new Scanner(System.in);
System.out.println("Press any key to cancel....");
s.nextLine();
camelCtx.stop();
println "finished?"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment