Last active
November 7, 2016 12:37
-
-
Save milovtim/bf57b6e695c17f211a9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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