////请问该如何来实现?
当然是自己写程序实现。///将附件上传到web页面,然后发送出去,该怎么做?
上传是小问题,我用的jspsmartupload作的,james不直接提供添加删除用户的api,但是你可以改造数据库结构自己自己对数据库操作啊。最难的是自定义文件夹、配置,我还没有实现,虽然有思路,但不想写代码:(
去找james的文档来看吧,虽然比较痛苦,我就是这样过来的。

解决方案 »

  1.   


    To pigo(淡是水于火的相容)
    谢谢大哥的解答,那能把您的上传的代码帖出来呢,小弟还有一是不明,比如,我通过web浏览方式看我的收件箱,那么整个邮件是存在一起的,连同附件一起,那么请文这时候怎么处理,至少在显示上怎么处理
      

  2.   

    可以用rmi调用james服务器程序实现用户的添加,修改等...
    详见\james-2.2.0-src\proposals\rmi-remotemanagerjmx方式好象还没实现吧,不懂。
      

  3.   

    小弟已经写完,谢谢leozmy(麦庄) 的提醒,直接通过远程调用服务器上的命令行来实验,贴出来大家共享一下
    package com.hypersoft.ccm.util.mail;import java.net.Socket;
    import java.io.PrintWriter;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.net.UnknownHostException;
    import java.io.InputStreamReader;
    import java.io.PrintStream;/**
     * @author wangjb
     *
     * To change the template for this generated type comment go to
     * Window>Preferences>Java>Code Generation>Code and Comments
     */
    public class MailServerMng {
    private String serverAddress = "localhost";
    private int port = 4555;
    private String userId = "root"; // administrators userid
    private String password = "root"; private Socket connectionSocket = null;
    private PrintStream out = System.err;
    private BufferedReader in = null;
    private boolean connectedStatus; public MailServerMng() {
    }
    public MailServerMng(String server, int port, String uid, String pwd) {
    this.userId = uid;
    this.password = pwd;
    this.serverAddress = server;
    this.port = port;
            
    this.connectedStatus = connect();
    } //methods
    public void ensure(String _userid, String _password, String _domain)
    throws IOException {
    if (serverAddress.equalsIgnoreCase(_domain)) {
    if (!isConnected()) {
    connect();
    }
    if (verifyUser(_userid)) {
    // user exists in james and changing password
    if (null != _password && 0 < _password.length())
    changePassword(_userid, _password);
    } else
    addUser(_userid, _password);
    // user was not in james and should
    } else {
    if (!isConnected()) {
    connect();
    }
    if (verifyUser(_userid)) { // user exists in James and should not
    delUser(_userid);
    }
    }
    } public boolean isConnected() {
    return this.connectedStatus;
    } private void disconnect() {
    try {
    this.out.println("quit");
    this.out.close();
    this.in.close();
    this.connectionSocket.close();
    this.connectedStatus = false;
    return;
    } catch (IOException e) {
    this.connectedStatus = false;
    log("Couldn't get I/O for " + "the connection to server.");
    return;
    }
    } public boolean connect() {
    try {
    this.connectionSocket = new Socket(this.serverAddress, this.port);
    this.out =
    new PrintStream(connectionSocket.getOutputStream(), true);
    this.in =
    new BufferedReader(
    new InputStreamReader(connectionSocket.getInputStream()));
    //Login to the server
    String userInput;
    log(in.readLine());
    //wait for the connection
    out.println(this.userId);
    //send userid
    log(in.readLine());
    //wait for \n
    out.println(this.password);
    //send the password
    //log (in.readLine()); 
    if (in.readLine().indexOf("HELP") != -1) {
    this.connectedStatus = true;
    log("Server accepted connection");
    return true;
    } else {
    this.connectedStatus = false;
    log("Server refused connection");
    return false;
    }
    } catch (UnknownHostException e) {
    this.connectedStatus = false;
    log("Unable to connect to the host!");
    return false;
    } catch (IOException e) {
    System.err.println("erreur officiel : \n" + e);
    this.connectedStatus = false;
    log("Couldn't get I/O for " + "the connection to server.");
    return false;
    }
    } private String execute(String command) throws IOException {
    String serverSays;
    if (connectedStatus == false)
    connect();
    // now execute the command
    log("executing: -" + command + "-");
    out.println(command);
    out.println("###");
    String returnString = "";
    char[] inChars = new char[1];
    serverSays = in.readLine();
    while (serverSays != null && serverSays.endsWith("###") == false) {
    returnString += serverSays + "\n";
    serverSays = in.readLine();
    }
    // log("returning"+returnString);
    return returnString;
    } public boolean verifyUser(String userName) throws IOException {
    if (!isConnected())
    connect();
    if (!isConnected())
    log("broken"); // do something String response = execute("verify " + userName);
    //   verify if specified user exist
    boolean exists = false;
    if (null != response && -1 == response.indexOf("does not"))
    exists = true; return exists;
    } public boolean addUser(String userName, String password)
    throws IOException {
    if (!isConnected())
    connect();
    if (!isConnected())
    log("broken: no connection to James"); // do something
    String response = execute("adduser " + userName + " " + password);
    boolean exists = false;
    System.err.println("reponse : " + response);
    if (null != response) {
    if (0 <= response.indexOf("added")) {
    exists = true;
    } else if (0 <= response.indexOf("already")) {
    exists = false;
    }
    }
    return exists;
    } public boolean delUser(String _userName, String _domain)
    throws IOException {
    if (serverAddress.equalsIgnoreCase(_domain)) {
    return delUser(_userName);
    }
    return true; // well, he is not here!
    } public boolean delUser(String userName) throws IOException {
    if (!isConnected())
    connect();
    if (!isConnected())
    log("broken"); // do something boolean exists = false;
          
    String response = execute("deluser " + userName + " " + password);
    if (null != response) {
    } else if (0 <= response.indexOf("deleted")) {
    exists = true; // was deleted
    } else if (0 <= response.indexOf("Error")) {
    exists = true; // didn't exist }
    return exists;
    } public boolean setPassword(String userName, String password)
    throws IOException {
    if (!isConnected())
    connect();
    if (!isConnected())
    log("broken"); // do something boolean exists = false; String response = execute("setpassword " + userName + " " + password);
    if (null != response) {
    } else if (0 <= response.indexOf("reset")) {
    exists = true; // was deleted
    } else if (0 <= response.indexOf("Error")) {
    exists = true; // didn't exist }
    return exists;
    } public boolean changePassword(String userName, String password)
    throws IOException {
    //if (verifyUser(userName))  // james 2 added setpassword
    //    delUser(userName);
    return setPassword(userName, password);
    } private void log(String note) {
    System.err.println(getClass().getName() + " " + note);
    }}