I had a look in the reference doc, and Spring seems to have pretty good support for sending mail. However, I need to login to a mail account, read the messages, and download
I used Apache Commons Mail for this task:
import java.util.List;
import javax.activation.DataSource;
import javax.mail.internet.MimeMessage;
import org.apache.commons.mail.util.MimeMessageParser;
public List getAttachmentList(MimeMessage message) throws Exception {
msgParser = new MimeMessageParser(message);
msgParser.parse();
return msgParser.getAttachmentList();
}
From a DataSource object you can retrieve an InputStream (beside name and type) of the attachment (see API: http://docs.oracle.com/javase/6/docs/api/javax/activation/DataSource.html?is-external=true).