Ok this is my code mybe it not look pretty but it work:
1. First you must connect to zimbra admin SOAP service for example and get auth token and session ID:
Code:
import com.zimbra.common.service.ServiceException;
import com.zimbra.cs.service.account.AccountService;
import com.zimbra.cs.service.admin.AdminService;
import com.zimbra.soap.Element;
import com.zimbra.soap.SoapFaultException;
import com.zimbra.soap.SoapHttpTransport;
import com.zimbra.soap.ZimbraSoapContext;
Code:
SoapHttpTransport trans = null;
try {
trans = new SoapHttpTransport("https://youZimbraServer:7071/service/admin/soap/"
);
Element request = Element.XMLElement.mFactory .createElement(AdminService.AUTH_REQUEST);
request.addAttribute(AdminService.E_NAME,"admin@example.com",Element.DISP_CONTENT);
request.addAttribute(AdminService.E_PASSWORD, "password",
Element.DISP_CONTENT);
response = trans.invoke(request);
} catch (Exception e) {
e.printStackTrace();
}
String authToken = null;
// get the auth token out, no default, must be present or a service exception is thrown
try {
authToken = response.getAttribute(AccountService.E_AUTH_TOKEN);
} catch (ServiceException e) {
//
e.printStackTrace();
}
// get the session id, if not present, default to null
String sessionId = response.getAttribute(ZimbraSoapContext.E_SESSION_ID, null);
System.out.println(sessionId);
trans.setAuthToken(authToken);
if (sessionId != null)
trans.setSessionId(sessionId);
2. Now when you have a token and session ID you can send a request to create account:
Code:
Element accRequest = Element.XMLElement.mFactory.createElement(AdminService.CREATE_ACCOUNT_REQUEST);
accRequest.addElement(AdminService.E_NAME).setText("test@example.com");
accRequest.addElement(AdminService.E_PASSWORD).setText("examplepasswd");
//You can set another parametr for acconut for example:
//tagsRequest.addElement(AdminService.E_A).addAttribute("n", "zimbraPrefFromDisplay").setText("example");
//in response you get a all atribute for account
Element accResponse = null;
try {
accResponse = trans.invoke(accRequest);
} catch (SoapFaultException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(accResponse.prettyPrint()); 3. If all go ok on you console show samethig like that:
Code:
<CreateAccountResponse xmlns="urn:zimbraAdmin">
<account id="zimbra id" name="test@example.com">
<a n="zimbraPrefGalAutoCompleteEnabled">FALSE</a>
<a n="zimbraPrefGroupMailBy">conversation</a>
....another atribute for account
....
<a n="zimbraPrefCalendarInitialView">workWeek</a>
</account>
</CreateAccountResponse> 4. You must change bold element in code
5. It should work - sorry for my English I still learn this language