POP3: Require an STLS Upgrade Before Authentication
Connect to a provider that supports POP STLS on port 110, require the TLS upgrade, then authenticate and obtain a message count. Set PopSsl=false, Pop3Stls=true, and enable certificate verification. Replace the generic host and credentials with settings issued by that provider. Use the provider's OAuth or app-password policy where applicable.
The former example was mislabeled: it connected to Gmail on port 995 using implicit TLS and never performed STLS. Gmail's documented POP configuration remains pop.gmail.com:995 with PopSsl=true; use Gmail POP OAuth2 for that connection.
The required STLS setting fails if the upgrade is unavailable. An opportunistic setting can leave a connection unencrypted and is not used here.
See the Gmail SMTP, IMAP, and POP3 guide for current authentication choices and Gmail-specific examples.
Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.MailMan;
public class ChilkatExample {
public static void main(String[] args) {
// Assumes Chilkat is unlocked. See Global Unlock Sample.
MailMan mailman = new MailMan();
// Use a provider that explicitly supports POP STLS on port 110.
// Gmail documents implicit TLS on pop.gmail.com:995 instead.
mailman.setMailHost("pop.example.com");
mailman.setMailPort(110);
mailman.setPopSsl(false);
mailman.setPop3Stls(true);
mailman.setPop3StlsIfPossible(false);
mailman.setRequireSslCertVerify(true);
mailman.setPopUsername("user@example.com");
mailman.setPopPassword("YOUR_PROVIDER_ISSUED_PASSWORD");
try {
mailman.pop3BeginSession();
} catch (ChilkatException e) {
mailman.pop3EndSessionNoQuit();
System.out.println("POP connection or authentication failed. STLS must succeed before credentials are sent.");
return;
}
int count = mailman.checkMail();
if (count < 0) {
mailman.pop3EndSessionNoQuit();
System.out.println("Could not obtain the POP message count.");
return;
}
System.out.println("Available POP messages: " + count);
try {
mailman.pop3EndSession();
} catch (ChilkatException e) {
System.out.println("The count was obtained, but closing the POP session failed.");
}
}
}