MailReceiver

public class MailReceiver extends MailConnector

MailReceiver is a mail connector for making connections to incoming mail servers.

Author:Hugo Y. K. Lam

Constructors

MailReceiver

public MailReceiver(String host, String username, String password)

Creates a new instance of MailReceiver. The default protocol is POP3.

Parameters:
  • host – the mail host.
  • username – the user name for authentication.
  • password – the password for authentication.

MailReceiver

public MailReceiver(String protocol, String host, String username, String password)

Creates a new instance of MailReceiver.

Parameters:
  • protocol – the mail protocol.
  • host – the mail host.
  • username – the user name for authentication.
  • password – the password for authentication.

Methods

connect

public synchronized void connect()

Connects to the incoming mail server.

Throws:
  • ConnectionException – if unable to connect to the incoming mail server or a connection to the server has already been established.

disconnect

public synchronized void disconnect()

Disconnects from the incoming mail server.

Throws:
  • ConnectionException – if unable to disconnect from the incoming mail server or the connection to the server has not been established.

openFolder

public synchronized Folder openFolder(String folderName)

Opens a specified folder for read-write access.

Parameters:
  • folderName – the name of the folder to be opened.
Throws:
  • ConnectionException – if unable to open the specified folder or the connection to the incoming mail server has not yet been established.
Returns:

the opened folder.

openFolder

public synchronized Folder openFolder(String folderName, boolean readOnly)

Opens a specified folder.

Parameters:
  • folderName – the name of the folder to be opened.
  • readOnly – true if the folder should be readonly.
Throws:
  • ConnectionException – if unable to open the specified folder or the connection to the incoming mail server has not yet been established.
Returns:

the opened folder.

openInbox

public synchronized Folder openInbox()

Opens the inbox for read-write access.

Throws:
  • ConnectionException – if unable to open the inbox or the connection to the incoming mail server has not yet been established.
Returns:

the opened inbox.