Get All Message On Server : Email Server « Email « Java

Get All Message On Server

import java.util.Properties;

import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.URLName;

public class MainClass {

  public static void main(String[] args) throws Exception {
    URLName server = new URLName("protocol://username:password@host/foldername");

    Session session = Session.getDefaultInstance(new Properties(), null);

    Folder folder = session.getFolder(server);
    if (folder == null) {
      System.out.println("Folder " + server.getFile() + " not found.");

    // Get the messages from the server
    Message[] messages = folder.getMessages();
    for (int i = 0; i < messages.length; i++) {
      System.out.println("------------ Message " + (i + 1) + " ------------");


       2,325 k)

Related examples in the same category

1.Search the given folder for messages matching the given criteriaSearch the given folder for messages matching the given criteria
2.List information about folders
3.Copy a specified number of messages from one folder to another folder
4.Copy folder hierarchies between different Stores
5.MOVE messages between mailboxes
6.Show the namespaces supported by a store