0

I'm trying to get all the domain account's inbox mail using Soap Api to fetch Zimbra mail.

I have the following code to get the particular account inbox mail, but now i need to fetch all the domain accounts inbox mail using admin account.

import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.Properties;
import javax.xml.soap.SOAPMessage;

import com.astidian.zimbra.ws.Marshaller;
import com.astidian.zimbra.ws.SOAPFaultException;
import com.astidian.zimbra.ws.SoapInterface;
import com.astidian.zimbra.ws.messages.AuthRequest;
import com.astidian.zimbra.ws.messages.AuthResponse;
import com.astidian.zimbra.ws.messages.ContextHeader;
import com.astidian.zimbra.ws.messages.SearchRequest;
import com.astidian.zimbra.ws.messages.SearchResponse;

public class Test {
    public static void main(String[] args) throws Exception {
        Properties p = new Properties();
        p.load(Test.class.getResourceAsStream("test.properties"));
        URL u = new URL(p.getProperty("url"));

        SOAPMessage m = SoapInterface.newMessage();
        AuthRequest authreq = new AuthRequest();
        authreq.account = new AuthRequest.Account();
        authreq.account.by = "name";
        authreq.account.name = p.getProperty("user");
        authreq.password = "bogus-fake";
//        authreq.password = "7dw9T9Gb";
        Marshaller.marshal(m.getSOAPBody(), authreq);
       SoapInterface.setDebug(true);
        m = SoapInterface.call(m, u);
        try {
            Marshaller.unmarshal(AuthResponse.class, m);
            throw new IllegalStateException("soap fault expected");
        }
        catch (SOAPFaultException e) {
            System.out.println("\nFault Code: " + e.code.value);
            System.out.println("Fault reason: " + e.reason.text);
        }

        m = SoapInterface.newMessage();
        authreq.password = p.getProperty("pass");
        Marshaller.marshal(m.getSOAPBody(), authreq);
        m = SoapInterface.call(m, u);
        AuthResponse authresp = Marshaller.unmarshal(AuthResponse.class, m);

        System.out.println("\n Authtoken: " + authresp.authToken);

        ///////////////////////////////////////////////////////////////////////

        ContextHeader header = new ContextHeader();
        header.authToken = authresp.authToken;
        /** Getting Week start Date **/
        Calendar c = GregorianCalendar.getInstance();
        c.setFirstDayOfWeek(Calendar.MONDAY);
        // Set the calendar to monday of the current week
        c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        // Print dates of the current week starting on Monday
        DateFormat df = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault());
        String week_startDate = "";
        week_startDate = df.format(c.getTime());

        m = SoapInterface.newMessage();
        SearchRequest searchreq = new SearchRequest();
        searchreq.query = "in:inbox AND is:unread";//AND date:>="+week_startDate;
        searchreq.type = "message";
        searchreq.fetch = "all";
        Marshaller.marshal(m.getSOAPHeader(), header);
        Marshaller.marshal(m.getSOAPBody(), searchreq);

        m = SoapInterface.call(m, u);
        SearchResponse searchresp = Marshaller.unmarshal(
                SearchResponse.class, m);

        for (SearchResponse.Message msg : searchresp.messages) {
            System.out.printf("From: %s <%s>\n",
                    msg.sender.fullName, msg.sender.emailAddress);
            System.out.println("Subject: " + msg.subject);
            System.out.println("Fragment:\n" + msg.fragment);
            System.out.println();
        }

    }
}

Please can anyone help me to get all domains account inbox mail using admin account connection !!!

US-1234
  • 1,519
  • 4
  • 24
  • 61
  • What about your current code does not work? – Jim Garrison Sep 28 '15 at 05:30
  • It just connects to single account, now i want to connect as admin account and to get all accounts inbox mail from zimbra only using admin account. – US-1234 Sep 28 '15 at 05:33
  • OK, so what have you tried so far? Have you read the API documentation? Have you written and tested any code? You need to have made some attempt to solve the problem before posting here. – Jim Garrison Sep 28 '15 at 05:38
  • yes above code works, I have used getAllaccountsresponse () to get all account from particular domain, Now my only doubt is which method is used to get all inbox mails of all accounts using admin account connection – US-1234 Sep 28 '15 at 05:39
  • That is where you go to the API documentation to see if that's an available function. Do you know for sure that the Zimbra API allows the Admin user to read people's mail? – Jim Garrison Sep 28 '15 at 05:50
  • Can you give me the link to get API documentation ? – US-1234 Sep 28 '15 at 05:59
  • Can you tell the java used client please.. @US-1234 – Houssem Yahiaoui Jun 23 '16 at 14:35

0 Answers0