1

Topic: Creating a new account using Java

==== REQUIRED BASIC INFO OF YOUR IREDMAIL SERVER ====
- iRedMail version (check /etc/iredmail-release): 0.9.9
- Deployed with iRedMail Easy or the downloadable installer? downloadable
- Linux/BSD distribution name and version: Centos 7
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): LDAP
- Web server (Apache or Nginx): Nginx
- Manage mail accounts with iRedAdmin-Pro? Yes
- [IMPORTANT] Related original log or error message is required if you're experiencing an issue.
====

I'm attempting to create a new e-mail user using Java.   I'm accessing /iredadmin/api/login and receiving the "iRedAdmin-Pro-ldap" cookie containing the session id and a 200 return status.   When I attempt to create a user accessing /iredadmin/api/user/<email> I receive a status of 200, but no user appears in iRedAdminPro.   

Is there a log which would provide me with additional details on what is going wrong?

I'm using Apache HttpComponents 4.5 (https://hc.apache.org) and the following code:

        CloseableHttpClient iRed = HttpClients.createDefault();
        HttpPost iRedPost = new HttpPost("https://(server)/iredadmin/api/login");
        List<NameValuePair> postData = new ArrayList<NameValuePair>();
        postData.add(new BasicNameValuePair("username","(postmaster account)"));
        postData.add(new BasicNameValuePair("password","(postmaster password)"));
        iRedPost.setEntity(new UrlEncodedFormEntity(postData));
        CloseableHttpResponse response = iRed.execute(iRedPost);
        System.out.println("Login status: " + response.getStatusLine().getStatusCode());
        Header[] headers = response.getHeaders("Set-Cookie");
        for (Header h : headers) {
            System.out.println(h.getValue().toString());
        }
        iRedPost = new HttpPost("https://(server)/iredadmin/api/user/(new e-mail address)");
        postData = new ArrayList<NameValuePair>();
        postData.add(new BasicNameValuePair("cn","Test Account"));
        postData.add(new BasicNameValuePair("password","(new password)"));
        postData.add(new BasicNameValuePair("mailQuota","4096"));
        iRedPost.setEntity(new UrlEncodedFormEntity(postData));
        System.out.println("Create user status: " + response.getStatusLine().getStatusCode());

Thanks,
Bob

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: Creating a new account using Java

iRedAdmin-Pro RESTful API will return a JSON string to your Java client, if some error happened and iRedAdmin-Pro can not create account, the JSON string contains detailed error message.
So, what's the JSON string you got after sent the request?

3

Re: Creating a new account using Java

ZhangHuangbin wrote:

iRedAdmin-Pro RESTful API will return a JSON string to your Java client, if some error happened and iRedAdmin-Pro can not create account, the JSON string contains detailed error message.
So, what's the JSON string you got after sent the request?


Ah!   When I received the return status of 200 I assumed all was ok and didn't look any further.   I've added code to check the JSON return.   The problem was simple:
PW_NO_SPECIAL_CHAR

I'm currently only running this in a test environment.  As a test I'm creating an account named test with a password of Password.   Once I've used a better password the problem has been solved.

My code is now creating accounts without a problem.

Thanks!
Bob

4

Re: Creating a new account using Java

bdushok wrote:

When I received the return status of 200 I assumed all was ok and didn't look any further.

This is mentioned in the "Summary" section of RESTful API document:
https://docs.iredmail.org/iredadmin-pro … ml#summary