Topic: JAVAMAIL

  Print this page

1.JAVAMAIL Copy to clipboard
Posted by: glddydyzcw
Posted on: 2003-04-02 08:24

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import java.io.*;

public class RetriveMail {
  public static void main(String[] args)
  {
    if (args.length!=3)
    {
     System.out.println("Usage :sendmail SMTPhost TOaddress FromAddress");
     System.exit(1);  
    }
    String host=args[0];
    String username=args[1];
    String password=args[2];
    int i;
    try{
      
      Properties props=new Properties();
  //    props.put("mail.smtp.host",host);
      Session session=Session.getDefaultInstance(props,null);

      Store store=session.getStore("pop3");
      store.connect(host,username,password);
      
      Folder folder=store.getFolder("Inbox");
      folder.open(Folder.READ_ONLY);
      
      Message messages[]=folder.getMessages();
      
      for (i=1;i<messages.length;i++)
       {
      System.out.println("1");
       System.out.println(i+":"+messages[i].getFrom()[0]+"\t"+messages[i].getSubject()+"\t"+messages[i].getSentDate()+"\n\n");
       messages[i].writeTo(System.out);
      }      
      folder.close(false);
      store.close();
      }
      catch (MessagingException me){
        System.out.println(me.getMessage());
      }
      catch (IOException e){
        System.out.println(e.getMessage());
      }
    }
    
}

怎么检索不到信呢???


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923