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 and Description |
---|
EmailContainer(EmailConnectionInfo connectionInfo)
Initializes a new instance of the
EmailContainer class. |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
dispose()
Releases the unmanaged resources used by the container.
|
EmailConnectionInfo |
getConnectionInfo()
Gets an information for connection with email server.
|
List<Container.Entity> |
getEntities()
Gets a collection of container's entities.
|
InputStream |
openEntityStream(Container.Entity entity)
Opens a stream with the content of the container's entity.
|
public EmailContainer(EmailConnectionInfo connectionInfo)
Initializes a new instance of the EmailContainer
class.
connectionInfo
- The information for connection with email server.public EmailConnectionInfo getConnectionInfo()
Gets an information for connection with email server.
EmailConnectionInfo
class with the information for connection with email server.public List<Container.Entity> getEntities()
Gets a collection of container's entities.
getEntities
in interface IContainer
public void dispose()
Releases the unmanaged resources used by the container.
public void close()
close
in interface AutoCloseable
public InputStream openEntityStream(Container.Entity entity)
Opens a stream with the content of the container's entity.
openEntityStream
in interface IContainer
entity
- A container's entity.Copyright © 2018. All rights reserved.