Sample code for 30+ languages & platforms
Java

Send a Raw POP3 Command

See more POP3 Examples

Demonstrates the Chilkat MailMan.Pop3SendRawCommand method, which sends a raw command to the POP3 server and returns the server's response. The second argument specifies the charset to use if the command contains non-US-ASCII characters. This example sends the POP3 STAT command within an open session.

Background: POP3 is a simple line-based text protocol — the client sends short commands like STAT, LIST, UIDL, or RETR and the server replies with +OK or -ERR. This method is an escape hatch for issuing a command Chilkat doesn't wrap directly, or a server-specific extension. Note that the session must already be open, since a raw command assumes an authenticated connection.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.MailMan;

public class ChilkatExample {

    public static void main(String[] args) {
        // Demonstrates the MailMan.Pop3SendRawCommand method, which sends a raw command to the POP3
        // server and returns the server's response.  The second argument is the charset used if the
        // command contains non-US-ASCII characters.

        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");

        String response;
        try {
            mailman.pop3BeginSession();

            // Send the raw POP3 STAT command, which returns the message count and maildrop size.
            response = mailman.pop3SendRawCommand("STAT", "us-ascii");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println("STAT response: " + response);

        try {
            mailman.pop3EndSession();
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }
    }
}