当前位置: 代码迷 >> Java相关 >> http://java.sun.com/上的邮件回复功能代码为什么不成功?
  详细解决方案

http://java.sun.com/上的邮件回复功能代码为什么不成功?

热度:469   发布时间:2007-11-25 03:56:28.0
http://java.sun.com/上的邮件回复功能代码为什么不成功?
[url]http://java.sun.com/developer/onlineTraining/JavaMail/exercises/MailReply/[/url]上有关javaMail邮件回复功能的代码。我在本地测试的时候并不成功。这是为什么?
代码如下:import java.io.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

public class ReplyExample {
  public static void main (String args[]) throws Exception {
    String host = args[0];
    String sendHost = args[1];
    String username = args[2];
    String password = args[3];
    String from = args[4];

    // Create empty properties
    Properties props = System.getProperties();
    props.put("mail.smtp.host", sendHost);

    // Get session
    Session session = Session.getDefaultInstance(props, null);

    // Get the store
    Store store = session.getStore("pop3");
    store.connect(host, username, password);

    // Get folder
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_ONLY);

    BufferedReader reader = new BufferedReader (
      new InputStreamReader(System.in));

    // Get directory
    Message message[] = folder.getMessages();
    for (int i=0, n=message.length; i<n; i++) {
       System.out.println(i + ": " + message[i].getFrom()[0]
         + "\t" + message[i].getSubject());

      System.out.println("Do you want to reply to the message? [YES to reply/QUIT to end]");
      String line = reader.readLine();
      if ("YES".equals(line)) {

        // Create a reply message

        // Set the from field

        // Create the reply content, copying over the original if text

        // Set the content

        // Send the message

      } else if ("QUIT".equals(line)) {
        break;
      }
    }

    // Close connection
    folder.close(false);
    store.close();
  }
}
搜索更多相关的解决方案: java  sun  代码  邮件  

----------------解决方案--------------------------------------------------------
  相关解决方案