Tag Archives: imap

accessing imap

accessing imap mailboxes is super easy with javax.mail… 

final Properties props = new Properties();
props.setProperty(“mail.store.protocol”, IMAP_PROTOCOL);
final Session session = Session.getInstance(props);

final Store store = session.getStore(IMAP_PROTOCOL);
store.connect(server, user, password);

final IMAPFolder imapFolder = (IMAPFolder) store.getFolder(“Inbox”);
imapFolder.open(Folder.READ_ONLY);

final FlagTerm ft = this.getFlagTerm(new Flags(Flags.Flag.SEEN), false);
final Message[] messages = imapFolder.search(ft);

for (int i = 0; i < messages.length; i++) {
  final long imapUid = imapFolder.getUID(messages[i]);
  final MimeMessage message = new MimeMessage((MimeMessage) messages[i]);
}

easy… main problem is, that the MimeMessage is directly linked to the imap Folder… so if you return the MimeMessages and close the imapFolder… accessing the MimeMessage dont work… 🙁

Solution? CopyConstructor

MimeMessage copyedMessage = new MimeMessage(message);

nuff said!

mule imap:connector

ok tryed some things with the mule imap:connector and its kinda cool… and its kinda crap… a few functions are really cool, but dont work as expected…

imap:connector

  • checkFrequency: milliseconds to try getting new mails on the imap-server
  • deleteReadMessage: deletes the message, after read
  • backupEnabled / bachupFolder: backups the read mail to the folder… the folder is localy, not on the imap-server (partly crap)
  • moveToFolder: moves the mail to the given folder after processing. if deleteReadMessage is true, the moved message is flagged deleted too (crap), if deleteReadMessage is false, the move is a copy (crap)

imap:inbound-endpoint

  • user (is containing a @, use %40 instead)
  • password
  • host
  • port

all in all it is a really powerful connector, which reads the mailbox frequently and can be used as perfect flow starter…  additionally it returns an MimeMessage, with all the Headers and so on… but on the other hand, it cant handle the mails on the imap server… it looks like the handling on the server needs to be implemented with a POJO… if this is the way to go is a complete new question…

imap

in my project at work we need to read a mail box… sounds not so easy, but actually is… mule imap:connector for the win 🙂

but testing this is a pain… first of all i needed a mail account with imap access… my company is really big an the processes to get such an email adress is huge… and yeah… we are an isp 😛 so just try to get a simple free email adress with imap… kinda hard… fastmail.fm is the solution…

could connect, but couldnt read or find directories… so had to connect with telnet, to find out everything…

in commandline:

  • telnet [host [port]] to connect
  • 1 LOGIN username password to log in (the 1 is important… imap needs numbers)
  • 1 LIST “*” “*” to list all mail boxes… no clue what the “*” are, but it has listed 🙂

this helped…