Java核心代码例程之:JavaMail ----PopMail.java
2008-01-05 08:39:47 来源:WEB开发网核心提示:import java.io.*;import java.util.*;import javax.mail.*;import javax.mail.internet.*;import javax.activation.*;/** * Demonstrate POP mail using JavaMail.Require
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
/**
* Demonstrate POP mail using JavaMail. Requires mail.jar activation.jar
* Sample run: java -cp .;mail.jar;activation.jar PopMail
**/
public class PopMail
{
public static void main(String args[]) throws Exception
{
String pop3Host="myhost.com", popUser="john", popPassWord="letmein";
session session = Session.getDefaultInstance(System.getPRoperties(), null);
Store store = session.getStore("pop3");
store.connect(pop3Host, -1, popUser, popPassword);
// Open the default folder
Folder folder = store.getDefaultFolder();
if (folder == null)
throw new NullPointerException("No default mail folder");
folder = folder.getFolder("INBOX");
if (folder == null)
throw new NullPointerException("Unable to get folder: " + folder);
// Get message count
folder.open(Folder.READ_WRITE);
int totalMessages = folder.getMessageCount();
if (totalMessages == 0)
{
System.out.println("No messages found in inbox");
folder.close(false);
赞助商链接