当前位置: 代码迷 >> Java Web开发 >> 使用james邮件服务器的邮件客户端怎么在程序中添加用户
  详细解决方案

使用james邮件服务器的邮件客户端怎么在程序中添加用户

热度:105   发布时间:2016-04-17 15:31:21.0
使用james邮件服务器的邮件客户端如何在程序中添加用户
用james服务器添加用户,有一种方式是在命令行里输telnet   ...4555   。
但是现在我需要在业务层里用程序实现添加用户到邮件服务器,我想肯定有相应的API可以调用,但是不知道是那些API。
        请知道的兄弟指点一下啊。

------解决方案--------------------
不用吧,俺用postfix做的虚拟域和虚拟用户,直接写条数据到数据库,postfix就自动建用户.
------解决方案--------------------
import com.ritetone.util.Config;
import com.ritetone.util.logger.Logger;
import java.io.PrintStream;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.util.ArrayList;
import org.apache.james.remotemanager.UserManager;

public class MailRmiClient
{

private String rmiURL;
private UserManager userManager;

public MailRmiClient()
{
try
{
rmiURL = Config.getProperty( "webmail ", "rmiinvoker ");
userManager = (UserManager)Naming.lookup(rmiURL);
}
catch(Exception e)
{
Logger.error( "Class MailRmiClient Method constructor() throw Exception ", e);
}
}

public boolean addUser(String username, String password)
throws RemoteException
{
boolean rtn = true;
rtn = userManager.addUser(username, password);
if(rtn)
Logger.info( "Class MailRmiClient.java Method addUser() adding user " + username + " ok ");
else
Logger.error( "Class MailRmiClient.java Method addUser() adding user " + username + " error ");
return rtn;
}

public boolean deleteUser(String username)
throws RemoteException
{
boolean rtn = true;
try
{
rtn = userManager.deleteUser(username);
}
catch(Exception e)
{
rtn = false;
Logger.error( "Class MailRmiClient.java Method deleteUser() remove user " + username + " - " + e.getMessage());
}
return rtn;
}

public boolean verifyUser(String username)
throws RemoteException
{
return userManager.verifyUser(username);
}

public int getCountUsers()
throws RemoteException
{
return userManager.getCountUsers();
}

public ArrayList getUserList()
throws RemoteException
{
return userManager.getUserList();
}

public boolean setPassword(String username, String password)
throws RemoteException
{
boolean rtn = true;
rtn = userManager.setPassword(username, password);
if(rtn)
Logger.info( "Class MailRmiClient Method setPassword() resetting password for user " + username + " ok ");
else
Logger.error( "Class MailRmiClient Method setPassword() resetting password for user " + username + " error ");
return rtn;
}