| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 769 人关注过本帖
标题:http://java.sun.com/上的邮件回复功能代码为什么不成功?
只看楼主 加入收藏
jdk2006
Rank: 1
等 级:新手上路
帖 子:244
专家分:0
注 册:2007-5-12
收藏
 问题点数:0 回复次数:0 
http://java.sun.com/上的邮件回复功能代码为什么不成功?
[url]http://java.[/url]上有关javaMail邮件回复功能的代码。我在本地测试的时候并不成功。这是为什么?
代码如下:import *;
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 代码 邮件 
2007-11-25 03:56
快速回复:http://java.sun.com/上的邮件回复功能代码为什么不成功?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012247 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved