Skip to content

Instantly share code, notes, and snippets.

@milovtim
Last active November 7, 2016 12:37
Show Gist options
  • Save milovtim/bf57b6e695c17f211a9b to your computer and use it in GitHub Desktop.
Save milovtim/bf57b6e695c17f211a9b to your computer and use it in GitHub Desktop.
import javax.mail.internet.InternetAddress
import javax.mail.Address
import javax.mail.Message
import javax.mail.Session
import javax.mail.Folder
def props = new Properties()
props.put 'mail.store.protocol', 'imaps'
def host = 'imap.yandex.ru'
def port = 993
def username = 'user'
def password = 'password'
def store = Session.getDefaultInstance(props, null).store
store.connect(host, port, username, password)
def inbox = store.getFolder('Inbox')
inbox.open(Folder.READ_ONLY)
def messages = inbox.messages
messages.each { Message message ->
def from = message.getFrom().collect {Address address ->
if (address instanceof InternetAddress)
address.address
else
address.toString()
}.join(';')
def subject = message.subject
println "$from\t$subject"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment