title: Groovy Imap Access
body: <p>I have following code</p>
  
  <pre><code>import javax.mail.*
  
  def host = "imap.gmail.com"
  def port = "993"
  def username = "username@gmail.com"
  def password = "password"
  
  Properties props = new Properties()
  props.setProperty("mail.store.protocol", "imap")
  props.setProperty("mail.imap.host", host)
  props.setProperty("mail.imap.port", port)
  def session = Session.getDefaultInstance(props, null)
  def store = session.getStore("imap")
  
  store.connect(host, username, password)
  def folder = store.getFolder("INBOX")
  folder.open(Folder.READ_WRITE)
  folder.messages.each { msg -&gt;
      println msg.subject
  }
  </code></pre>
  
  <p>but when I run this script it just hangs after compilation. What am I doing wrong ?</p>