com.groupdocs.parser

Interfaces

Classes

Exceptions

com.groupdocs.parser

Class EmailContainer

  • All Implemented Interfaces:
    IContainer, AutoCloseable


    public final class EmailContainer
    extends Object
    implements IContainer, AutoCloseable

    Provides a container for email servers.

    To retrieve a list of all emails Entities property is used:

     // Create connection info
     EmailConnectionInfo info = EmailConnectionInfo.createEwsConnectionInfo(
         "https://outlook.office365.com/ews/exchange.asmx",
         "username", 
         "password");
     // Create an email container
     IContainer container = new EmailContainer(info);
     // Iterate over emails
     for(Container.Entity entity : container.getEntities()) {
         System.out.println("Folder: " + entity.getPath().toString()); // A folder at server
         System.out.println("Subject: " + entity.get_Item(MetadataNames.SUBJECT)); // A subject of email
         System.out.println("From: " + entity.get_Item(MetadataNames.EMAIL_FROM)); // "From" address
         System.out.println("To: " + entity.get_Item(MetadataNames.EMAIL_TO)); // "To" addresses
     }
      

    To retrieve an email OpenEntityStream method is used:

     // Create connection info
     EmailConnectionInfo info = EmailConnectionInfo.createEwsConnectionInfo(
         "https://outlook.office365.com/ews/exchange.asmx",
         "username", 
         "password");
     // Create an email container
     IContainer container = new EmailContainer(info);
     // Iterate over emails
     for (Container.Entity entity : container.getEntities()) {
         // Create a stream with content of email
         java.io.InputStream stream = container.openEntityStream(entity); // or var stream = entity.OpenStream();
         // Create a text extractor for email
         EmailTextExtractor extractor = new EmailTextExtractor(stream);
         // Extract all the text from email
         System.out.println(extractor.extractAll());
     }
      
    • Constructor Detail

      • EmailContainer

        public EmailContainer(EmailConnectionInfo connectionInfo)

        Initializes a new instance of the EmailContainer class.

        Parameters:
        connectionInfo - The information for connection with email server.
    • Method Detail

      • getConnectionInfo

        public EmailConnectionInfo getConnectionInfo()

        Gets an information for connection with email server.

        Returns:
        An instance of EmailConnectionInfo class with the information for connection with email server.
      • dispose

        public void dispose()

        Releases the unmanaged resources used by the container.

      • openEntityStream

        public InputStream openEntityStream(Container.Entity entity)

        Opens a stream with the content of the container's entity.

        Specified by:
        openEntityStream in interface IContainer
        Parameters:
        entity - A container's entity.
        Returns:
        A stream with the content of the container's entity.