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

JavaMail: How to read Yahoo and Gmail inboxes

JavaMail: How to read Yahoo and Gmail inboxes
{filelink=1007}

import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Store;
public class Java_Email {
 private static void Read_Message(final String host, final String username, final String password)
 	throws  Exception
 {
    // Set the connection parameters
 	Session session = Session.getDefaultInstance(new Properties(),
 	    	 new Authenticator()
    	 {
    	 	  public PasswordAuthentication getPasswordAuthentication()
    	 	  	     {
                  return new PasswordAuthentication(username, password);
                     }
    	 }
    	 	);
    Store store = session.getStore("pop3");
    // Open the connection
     store.connect(host,username, password);
 	 System.out.println ("You're now connected to "+host);
 	// Opening the mailbox
 	 Folder inbox = store.getFolder("INBOX");
    if (inbox == null) {
      System.out.println("INBOX not found");
      System.exit(1);
    }
    inbox.open(Folder.READ_ONLY);
    // Select all messages in current folder(inbox)
    Message[] messages = inbox.getMessages();
    // print selected messages
    System.out.println ("Inbox message count: "+messages.length+" message(s)");
    System.out.println ();
    // display one message
    if(messages.length>=1)
    	messages[1].writeTo(System.out);
 	 store.close();
 }
  public static void main(String[] args) throws Exception
  {
  	 // GMail Example
     Java_Email.Read_Message("pop.gmail.com","username","test***pase");
     // Yahoo Example
     Java_Email.Read_Message("pop.mail.yahoo.ca","username","test***pase");
  }
}

Users who found this page were searching for:

  • select Jbutton java swing
  • how to read gmails whit a programme
  • python bind
  • javamail yahoo read inbox
  • javamail yahoo Gmail 一覧
  • check if an element exists in a dictionary python
  • read yahoo mail using java
  • how to read mail from yahoo with java mailing

No comments yet.

Leave a Comment