You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-user@james.apache.org by Radha K <ra...@gmail.com> on 2005/11/28 12:19:40 UTC
add user to james through java class or web UI
Hi,
Is it possible to add users to James though a Java class. If possible , I
need the solution.
Thanks
--
K. RADHA
RE: add user to james through java class or web UI
Posted by Gaurav Handa <ga...@amsoft.net>.
The way I did it was by using a telnet client to programmatically telnet to
port 4555 and sending user add commands through output stream.. For this you
need a telnet client (eg. inetFactory.jar from jscape).
import com.jscape.inet.telnet.*;
import java.io.*;
public class TelnetClient extends TelnetAdapter {
private Telnet telnet = null;
private OutputStream output = null;
private static BufferedReader reader = null;
private boolean connected = false;
public TelnetClient(String hostname, String LoginName, String LoginPasswd)
throws IOException {
String input = null;
// create new Telnet instance
telnet = new Telnet(hostname);
telnet.setPort(4555);
// register this class as TelnetListener
telnet.addTelnetListener(this);
try{
// establish Telnet connection
telnet.connect();
}catch(Exception ex){
System.out.println("exception caught while connecting" +ex);
}
connected = true;
// get output stream
output = telnet.getOutputStream();
// sends all data entered at console to Telnet server
System.out.println("going to add user through telnet session");
String serverLogin = "root";
String serverPasswd = "root";
input = "adduser " + LoginName + " " + LoginPasswd;
if (connected) {
((TelnetOutputStream) output).println(serverLogin);
int command = telnet.TSC_CR;
((TelnetOutputStream) output).println(serverPasswd);
command = telnet.TSC_CR;
((TelnetOutputStream) output).println(input);
} else {
//break;
}
telnet.disconnect();
}
Rgds,
Gaurav Handa
-----Original Message-----
From: Radha K [mailto:radha.k@gmail.com]
Sent: Monday, November 28, 2005 5:09 PM
To: James Users List
Subject: Re: add user to james through java class or web UI
are there any other solutions for this??
---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org
Re: add user to james through java class or web UI
Posted by Radha K <ra...@gmail.com>.
are there any other solutions for this??
On 11/28/05, Daniel Soriano <ds...@isoco.com> wrote:
>
> A very basic solution:
>
> import java.io.*;
> import java.net.*;
> import java.util.*;
>
> public class TestJamesRemoteManager {
> static Socket socket;
> static DataInputStream in;
> static DataOutputStream out;
> static PrintStream prout;
> static String[] commands = {"root","n0tiene","user list-test",
> "adduser mysuer@domain.com apasswd", "listusers"};
>
>
> public static void main(String s[]) {
> /*
> ** testMAILMIME [server] [destinataire]
> */
> TestJamesRemoteManager t = new TestJamesRemoteManager();
> System.out.println(t.sendCommands("localhost",4555,commands));
> }
>
> public Vector sendCommands(String mailServer, int SMTPport, String[]
> service_commands) {
> Vector result = new Vector();
> try {
> Socket s = new Socket(mailServer, SMTPport);
> BufferedReader in = new BufferedReader
> (new InputStreamReader(s.getInputStream(), "8859_1"));
> BufferedWriter out = new BufferedWriter
> (new OutputStreamWriter(s.getOutputStream(), "8859_1"));
>
> // here you are supposed to receive initial messages
> readln(in);
> readln(in);
> readln(in);
>
> // here you are supposed to send your commands
> for (int i=0;i<service_commands.length;i++)
> result.addAll(sendln(in, out, service_commands[i]));
>
> s.close();
> }
> catch (Exception e) {
> e.printStackTrace();
> }
>
> return result;
> }
> public void readln(BufferedReader in) {
> try {
> String s = in.readLine();
> //System.out.println(s);
> }
> catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> public Vector sendln(BufferedReader in, BufferedWriter out, String s)
> {
> Vector sb = new Vector();
> try {
> out.write(s + "\r\n");
> out.flush();
> s = in.readLine();
> while ( (in.ready()) ) {
> sb.add(s);
> s = in.readLine();
> }
> sb.add(s);
> }
> catch (Exception e) {
> e.printStackTrace();
> }
>
> return sb;
> }
>
> public void sendln(BufferedWriter out, String s) {
> try {
> out.write(s + "\r\n");
> out.flush();
> }
> catch (Exception e) {
> e.printStackTrace();
> }
> }
> }
>
> -----Original Message-----
> From: Radha K [mailto:radha.k@gmail.com]
> Sent: lunes, 28 de noviembre de 2005 12:20
> To: server-user@james.apache.org
> Subject: add user to james through java class or web UI
>
>
> Hi,
>
> Is it possible to add users to James though a Java class. If possible ,
> I need the solution.
>
>
> Thanks
> --
> K. RADHA
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
> For additional commands, e-mail: server-user-help@james.apache.org
>
>
--
K. RADHA
RE: add user to james through java class or web UI
Posted by Daniel Soriano <ds...@isoco.com>.
A very basic solution:
import java.io.*;
import java.net.*;
import java.util.*;
public class TestJamesRemoteManager {
static Socket socket;
static DataInputStream in;
static DataOutputStream out;
static PrintStream prout;
static String[] commands = {"root","n0tiene","user list-test",
"adduser mysuer@domain.com apasswd", "listusers"};
public static void main(String s[]) {
/*
** testMAILMIME [server] [destinataire]
*/
TestJamesRemoteManager t = new TestJamesRemoteManager();
System.out.println(t.sendCommands("localhost",4555,commands));
}
public Vector sendCommands(String mailServer, int SMTPport, String[]
service_commands) {
Vector result = new Vector();
try {
Socket s = new Socket(mailServer, SMTPport);
BufferedReader in = new BufferedReader
(new InputStreamReader(s.getInputStream(), "8859_1"));
BufferedWriter out = new BufferedWriter
(new OutputStreamWriter(s.getOutputStream(), "8859_1"));
// here you are supposed to receive initial messages
readln(in);
readln(in);
readln(in);
// here you are supposed to send your commands
for (int i=0;i<service_commands.length;i++)
result.addAll(sendln(in, out, service_commands[i]));
s.close();
}
catch (Exception e) {
e.printStackTrace();
}
return result;
}
public void readln(BufferedReader in) {
try {
String s = in.readLine();
//System.out.println(s);
}
catch (Exception e) {
e.printStackTrace();
}
}
public Vector sendln(BufferedReader in, BufferedWriter out, String s)
{
Vector sb = new Vector();
try {
out.write(s + "\r\n");
out.flush();
s = in.readLine();
while ( (in.ready()) ) {
sb.add(s);
s = in.readLine();
}
sb.add(s);
}
catch (Exception e) {
e.printStackTrace();
}
return sb;
}
public void sendln(BufferedWriter out, String s) {
try {
out.write(s + "\r\n");
out.flush();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
-----Original Message-----
From: Radha K [mailto:radha.k@gmail.com]
Sent: lunes, 28 de noviembre de 2005 12:20
To: server-user@james.apache.org
Subject: add user to james through java class or web UI
Hi,
Is it possible to add users to James though a Java class. If possible ,
I need the solution.
Thanks
--
K. RADHA
---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org