Java
Chilkat2 Java
Explicitly Begin a POP3 Session
See more POP3 Examples
Demonstrates the Chilkat MailMan.Pop3BeginSession method, which explicitly begins a POP3 session by connecting to the POP3 server and authenticating using the current POP3 property settings. Calling it is optional. This example begins a session, performs a mailbox operation, and ends the session.
Background:
Pop3BeginSession combines connecting and authenticating into one call. Chilkat does this automatically when a mailbox operation needs it, so the value of calling it explicitly is control: you open one session, perform several operations against it, and close it with Pop3EndSession — avoiding repeated connect/authenticate round trips and keeping deletion marks within a single, well-defined session.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.MailMan;
public class ChilkatExample {
public static void main(String[] args) {
// Demonstrates the MailMan.Pop3BeginSession method, which explicitly begins a POP3 session
// by connecting to the POP3 server and authenticating using the current POP3 property
// settings.
MailMan mailman = new MailMan();
// Configure the POP3 server connection.
mailman.setMailHost("pop.example.com");
mailman.setMailPort(995);
mailman.setPopSsl(true);
mailman.setPopUsername("user@example.com");
mailman.setPopPassword("myPassword");
// Explicitly begin the POP3 session (connect + authenticate).
try {
mailman.pop3BeginSession();
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// Perform one or more mailbox operations within this single session.
System.out.println("Mailbox count: " + mailman.getMailboxCount());
// End the session when finished.
try {
mailman.pop3EndSession();
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("POP3 session completed.");
}
}