Tuesday, July 15, 2008

How To Talk To JAMES administration from Ruby On Rails

JAMES: using it as a mail server through which we sent emails is trivial. The real power of using JAMES is when you can receive, filter and sort through emails. The first task was to talk to it and to get it to it do some admin tasks like creating a user account (1)

People apparently are trying but still nothing in terms of a packaged solution or a clean/ documented / usable interface.

Anyways amongst the approaches taken I decided to try to "telnet" to the JAMES server and create an account from there. This is how we do it manually:
The same thing (as in above) we shall do programmatically:
This is the code where you can login to JAMES and create a user account from Ruby on Rails :

require 'net/telnet'


def createEmailAccount
tn = Net::Telnet.new({"Host"=> "localhost",
"Port"=> 4555,
"Output_log" => "james_telnet_output_log.log", # default: nil (no output)
"Dump_log" => "james_telnet_dump_log.log" # default: nil (no output)
})
#tn.waitfor (/Login id:/i) { |s| puts s }
sleep 1
tn.puts('root'){|s| puts s}
#tn.waitfor (/Password:/i) { |s| puts s }
sleep 1
tn.puts('password'){|s| puts s}
sleep 1
#tn.waitfor( /Welcome root. HELP for a list of commands/i ) { |c| print c }
username = params[:user][:login] # this is obtained from what the user entered
pwd = params[:user][:login] # any user entered
tn.puts("adduser " + username + " " + pwd ) { |c| print c }
sleep 2
tn.puts("quit")
sleep 1
tn.close
end

As you can see this all just to enter the command "adduser USERNAME PWD" on a console's command line. This has potential of doing all administration from the web front end.

Oh, the sleep calls are necessary :( that is one of the quirks of using telnet.

No comments:

Total Pageviews

Popular Posts