佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1096|回复: 7

Java Programming ProbleM.......

[复制链接]
发表于 30-1-2007 03:01 PM | 显示全部楼层 |阅读模式
怎么当我执行这个程式时。它出现将的
Usage: java com.lotontech.mail.SimpleReceiver"+" popServer popUser popPassword");
和我的 POPSERVER,POPUSER,POPPASSWORD 应该写在那里
谢谢大家帮忙
  
  
  
   import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;
  
/**
* A simple email receiver class.
*/
public class SimpleReceiver{
/**
¡¡* Main method to receive messages from the mail server specified
¡¡* as command line arguments.
¡¡*/
     public static void main(String args[]){
         try{
             String popServer=args[0];
             String popUser=args[1];
             String popPassword=args[2];
             receive(popServer, popUser, popPassword);
         }catch (Exception ex){
             System.out.println("Usage: java com.lotontech.mail.SimpleReceiver"+" popServer popUser popPassword");
         }
         System.exit(0);
     }
     /**
     * " receive" method to fetch messages and process them.
     */
     public static void receive(String popServer, String popUser, String popPassword){
         Store store=null;
         Folder folder=null;
         try{
             // -- Get hold of the default session --
             Properties props = System.getProperties();
             Session session = Session.getDefaultInstance(props, null);
             // -- Get hold of a POP3 message store, and connect to it --
             store = session.getStore("pop3");
             store.connect(popServer, popUser, popPassword);
             // -- Try to get hold of the default folder --
             folder = store.getDefaultFolder();
             if (folder == null) throw new Exception("No default folder");
             // -- ...and its INBOX --
             folder = folder.getFolder("INBOX");
             if (folder == null) throw new Exception("No POP3 INBOX");
             // -- Open the folder for read only --
             folder.open(Folder.READ_ONLY);
             // -- Get the message wrappers and process them --
             Message[] msgs = folder.getMessages();
             for (int msgNum = 0; msgNum < msgs.length; msgNum++){
                 printMessage(msgs[msgNum]);
             }
         }catch (Exception ex){
             ex.printStackTrace();
         }
         finally{
         // -- Close down nicely --
             try{
                 if (folder!=null) folder.close(false);
                 if (store!=null) store.close();
             }catch (Exception ex2) {
                 ex2.printStackTrace();
             }
         }
     }
     /**
     * "printMessage()" method to print a message.
     */
     public static void printMessage(Message message){
         try{
             // Get the header information
             String from=((InternetAddress)message.getFrom()[0]).getPersonal();
             if (from==null) from=((InternetAddress)message.getFrom()[0]).getAddress();
             System.out.println("FROM: "+from);
             String subject=message.getSubject();
             System.out.println("SUBJECT: "+subject);
             // -- Get the message part (i.e. the message itself) --
             Part messagePart=message;
             Object content=messagePart.getContent();
             // -- or its first body part if it is a multipart message --
             if (content instanceof Multipart){
                 messagePart=((Multipart)content).getBodyPart(0);
                 System.out.println("[ Multipart Message ]");
             }
             // -- Get the content type --
             String contentType=messagePart.getContentType();
             // -- If the content is plain text, we can print it --
             System.out.println("CONTENT:"+contentType);
             if (contentType.startsWith("text/plain")||
                 contentType.startsWith("text/html")){
                 InputStream is = messagePart.getInputStream();
                 BufferedReader reader=new BufferedReader(new InputStreamReader(is));
                 String thisLine=reader.readLine();
                 while (thisLine!=null){
                     System.out.println(thisLine);
                     thisLine=reader.readLine();
                 }
             }
             System.out.println("-----------------------------");
         }catch (Exception ex){
             ex.printStackTrace();
         }
     }
}
回复

使用道具 举报


ADVERTISEMENT

发表于 30-1-2007 03:11 PM | 显示全部楼层
把System.out.println("Usage: java com.lotontech.mail.SimpleReceiver"+" popServer popUser popPassword");
换成System.out.println(ex);
看看它出现什么结果。。。。
回复

使用道具 举报

 楼主| 发表于 30-1-2007 03:20 PM | 显示全部楼层
还是不行,结果是show “ ex” only
回复

使用道具 举报

发表于 30-1-2007 04:38 PM | 显示全部楼层
Usage: java com.lotontech.mail.SimpleReceiver popServer popUser popPassword")

它已經跟你說用法了啊,你執行的時候要自己打參數進去。
如果你的程式檔名叫做SimpleReceiver.java,那麼compile之後會產生SimpleReceiver.class的binary執行檔。
在Command Prompt打以下的指令就可以了。
  1. java SimpleReceiver popServer popUser popPassword[enter]
复制代码

其中popServer是指pop3 server的IP或者domain name
popUser表示pop3 server的username
popPassword表示pop3 server的password
回复

使用道具 举报

 楼主| 发表于 30-1-2007 05:10 PM | 显示全部楼层

回复 #4 MaokeJackson 的帖子

在Command Prompt打以下的指令了,还是不行,

“javax.mail.messagingException : connect  failed;
Nested exception is
        Java.net.unknowHostException :popServer
        At com.sun.mail.pop3.POP3Store.protocolConnect (POP3Store.java)
等等`

compile之後會没有產生SimpleReceiver.class的binary執行檔哦
回复

使用道具 举报

 楼主| 发表于 30-1-2007 05:33 PM | 显示全部楼层
在Command Prompt打以下的指令了
java SimpleReceiver pop.gmail.com mylover84@gmail.com *****[enter]

show tis
javax.mail.authenticationFailedException : EOF on socket
    at com.sun.mail.pop3.POP3Store.protocolConnect(pop3Store.java:146)

.......
回复

使用道具 举报

Follow Us
发表于 30-1-2007 07:20 PM | 显示全部楼层
gmail使用ssl,试试看修改以下:
1.session.getStore("pop3s");
2.store.connect(popServer, port, popUser, popPassword); //port=995
回复

使用道具 举报

发表于 31-1-2007 12:05 AM | 显示全部楼层
原帖由 迷途羔羊 于 30-1-2007 05:33 PM 发表
在Command Prompt打以下的指令了
java SimpleReceiver pop.gmail.com mylover84@gmail.com *****

show tis
javax.mail.authenticationFailedException : EOF on socket
    at com.sun.mail.pop3.POP3St ...

username是指mylover84,後面的@gmail.com不用
回复

使用道具 举报


ADVERTISEMENT

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 28-8-2025 12:24 AM , Processed in 0.126863 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表