Java 使用管理员帐户-Zimbra获取所有域帐户收件箱邮件

Java 使用管理员帐户-Zimbra获取所有域帐户收件箱邮件,java,soap,zimbra,Java,Soap,Zimbra,我正在尝试使用Soap Api获取所有域帐户的收件箱邮件,以获取Zimbra邮件 我有以下代码来获取特定帐户的收件箱邮件,但现在我需要使用admin帐户获取所有域帐户的收件箱邮件 import java.net.URL; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.GregorianCalendar; import java.

我正在尝试使用Soap Api获取所有域帐户的收件箱邮件,以获取Zimbra邮件

我有以下代码来获取特定帐户的收件箱邮件,但现在我需要使用admin帐户获取所有域帐户的收件箱邮件

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();
        }

    }
}

请任何人都可以帮助我获得所有域帐户收件箱邮件使用管理员帐户连接

你当前的代码怎么办?它只连接到一个帐户,现在我想以管理员帐户的身份连接,并且只使用管理员帐户从zimbra获取所有帐户的收件箱邮件。好的,那么到目前为止你尝试了什么?你看过API文档了吗?您是否编写并测试过任何代码?在这里发布之前,您需要尝试解决这个问题。是的,上面的代码有效,我使用getAllaccountsresponse从特定域获取所有帐户,现在我唯一的疑问是使用哪种方法来获取使用管理员帐户连接的所有帐户的所有收件箱邮件这是您访问API文档以查看该函数是否可用的地方。你确定Zimbra API允许管理员用户阅读人们的邮件吗?