Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

JavaMail: Get Email Header

JavaMail: Get Email Header
{filelink=1011}

import java.util.Enumeration;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Folder;
import javax.mail.Header;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.URLName;
public class JavaMailHeader
 {
  public static void main(String[] args) throws Exception
  {
      URLName server = new URLName("protocol://nom_utilis@host/inbox");
    Session session = Session.getDefaultInstance(new Properties(),
    	 new Authenticator()
    	 {
    	 	  public PasswordAuthentication getPasswordAuthentication()
    	 	  	     {
                  return new PasswordAuthentication("username", "password");
                     }
    	 }
    	 	);
    Folder inbox = session.getFolder(server);
    if (inbox != null) {
      inbox.open(Folder.READ_ONLY);
 // print messages headers
      Message[] messages = inbox.getMessages();
      for (int i = 0; i < messages.length; i++) {
        System.out.println((i + 1));
        Enumeration headers = messages[i].getAllHeaders();
        while (headers.hasMoreElements()) {
          Header h = (Header) headers.nextElement();
          System.out.println(h.getName() + ": " + h.getValue());
        }
      }
      inbox.close(false);
    }
  }
}

Users who found this page were searching for:

  • pythonhow to generate a sequence of character using input file
  • python read file
  • how to compare Strings python
  • python convert string to unicode

No comments yet.

Leave a Comment