POP3-Post office Protocol.Pop3 protocol is used to fetch the message form the mail server using domain name, username and password. POP3 is extracting the mail form the mail server without using any browser.
Algorithm for POP3
Start the program for POP3
Import the necessary package java.mail.*; and java.mail.ineternet.*;
Declare the domain name, usernamae and password
By using connect function connect to the server
store.connect(host, username, password);
fetch the inbox status
Folder inbox = store.getFolder("INBOX");
By using for loop display the content of the message
for (int j = 0; j < messages.length; j++)
Finally terminate the pop3 program
source code java programming POP3
import javax.mail.internet.*;
import javax.mail.*;
import java.io.*;
import java.util.*;
public class ClientPOP3 {
public static void main(String[] args) {
Properties props = new Properties( );
String host = "mail.studentwebsite.org";
String username = "webadmin@studentwebsite.org";
String password = "student";
String provider = "pop3";
try {
Session session =
Session.getDefaultInstance(props, null);
Store store = session.getStore(provider);
store.connect(host, username, password);
Folder inbox = store.getFolder("INBOX");
if (inbox == null) {
System.out.println("No INBOX");
System.exit(1);
}
inbox.open(Folder.READ_ONLY);
Message[] messages = inbox.getMessages( );
for (int j = 0; j < messages.length; j++) {
System.out.println("---------------
Message " + (j+1) + " ---------------");
messages[j].writeTo(System.out);
}
inbox.close(false);
store.close( );
}
catch (Exception er) {
er.printStackTrace( );
}
}
}
Implementing POP3 Request using socket in java CS1404 INTERNET PROGRAMMING LABORATORY
Output CS1404 INTERNET PROGRAMMING LABORATORY pop3 request
C:\IPLAB>javac ClientPOP3.java
C:\IPLAB>java ClientPOP3