Thursday, July 15, 2010

JavaMail Events


  • JavaMail uses JDK 1.1 type event-handling mechanism. You can register your class as listeners to subclasses of MailEvent class. The Transport, Store and Folder classes generate such events.
  • A Transport object generates ConnectionEvent and TransportEvent. If the transport object connects successfully, it will fire the ConnectionEvent with the type set to OPENED. If the connection times out or is closed, ConnectionEvent with type CLOSED is generated. The sendMessage method of a Transport object generates a TransportEvent which contains information about the method's success or failure. The event object contains three arrays of address arrays: validSent[], validUnsent[] and invalid[]:
    1. MESSAGE_DELIVERED: Message sent to all recipients successfully. validSent[] contains all the addresses. validUnsent[] and invalid[] are null.
    2. MESSAGE_NOT_DELIVERED: When ValidSent[] is null, the message was not successfully sent to any recipients. validUnsent[] may have addresses that are valid. invalid[] may contain invalid addresses.
    3. MESSAGE_PARTIALLY_DELIVERED: Message was successfully sent to some recipients but not to all. ValidSent[] holds addresses of recipients to whom the message was sent. validUnsent[] holds valid addresses but the message wasn't sent to them. invalid[] holds invalid addresses.
  • A Store object generates ConnectionEvent (generated on a successful connection or close), StoreEvent (event.getMessageTypeALERT or NOTICE), FolderEvent (upon creation, deletion or renaming of a Folder). method returns either
  • A Folder object generates ConnectionEvent (a Folder is opened or closed), FolderEvent (this folder creates, deletes or renames) and MessageCountEvent (message count has changed, expunged Message objects are in the event).

No comments:

Post a Comment