Skip to content

Instantly share code, notes, and snippets.

@nbqx
Created October 10, 2010 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbqx/619274 to your computer and use it in GitHub Desktop.
Save nbqx/619274 to your computer and use it in GitHub Desktop.
// g100pon #13 gmailからメールを受信する
// IMAPでメールのリストつくるまであとはお好みで出力的なかんじです
import javax.mail.Session
import javax.mail.Folder
import java.util.Properties
@Grab(group="javax.mail", module="mail", version="latest.integration")
def user = "your_account@gmail.com"
def passwd = "your_password"
def props = new Properties()
props.setProperty("mail.store.protocol", "imaps")
def session = Session.getDefaultInstance(props,null)
def store = session.getStore("imaps")
store.connect("imap.gmail.com", user, passwd)
def inbox = store.getFolder("INBOX")
inbox.open(Folder.READ_ONLY)
def messages = inbox.messages.collect{mes->
[sentDate: mes.sentDate, subject:mes.subject, from: mes.from, content: mes.content]
}
//print messages as you like...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment