Thursday, March 22, 2012

How to read IMAP email with Groovy

There is quick snippet how to read email from Google IMAP with Groovy:

@Grab(group='javax.mail', module='mail', version='1.4')

import javax.mail.*
import java.util.Properties

def session = Session.getDefaultInstance(new Properties(["":"imaps", "":"", "mail.imaps.port":"993"]),null)
def store = session.getStore("imaps")
store.connect('', '', 'pass')
def folder = store.getFolder("INBOX")
folder.messages.each { msg ->
  println msg.content

No comments:

Post a Comment