1

發送電子郵件,我使用EWS發送在Exchange 2010郵件如下:不能與EWS的Java API

ExchangeService service = new ExchangeService(); 
ExchangeCredentials credentials = new WebCredentials(email, password); 
service.setCredentials(credentials); 
service.setUrl(new java.net.URI("https://" + host 
    + "/EWS/Exchange.asmx")); 
service.setTraceEnabled(true); 

EmailMessage msg = new EmailMessage(service); 
msg.setSubject("Hello world!"); 
msg.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Managed API.")); 
msg.getToRecipients().add("email"); 
msg.send(); 

郵件不會傳遞到收件箱,我不知道是什麼問題。 我啓用的跟蹤後,我得到如下:

<Trace Tag="EwsRequestHttpHeaders" Tid="1" Time="2012-10-14 11:13:46Z"> 
    POST /EWS/Exchange.asmx HTTP/1.1 
    Content-type : text/xml; charset=utf-8 
    Accept-Encoding : gzip,deflate 
    Keep-Alive : 300 
    User-Agent : ExchangeServicesClient/0.0.0.0 
    Connection : Keep-Alive 
    Accept : text/xml 
</Trace> 

<Trace Tag="EwsRequest" Tid="1" Time="2012-10-14 11:13:47Z"> 
    <?xml version="1.0" encoding="utf-8"?> 
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> 
    <soap:Header><t:RequestServerVersion Version="Exchange2010_SP1"></t:RequestServerVersion></soap:Header> 
    <soap:Body><m:CreateItem MessageDisposition="SendOnly"><m:Items><t:Message><t:Subject>Hello world!</t:Subject><t:Body BodyType="HTML">Sent using the EWS Managed API.</t:Body><t:ToRecipients><t:Mailbox><t:EmailAddress>[email protected]</t:EmailAddress></t:Mailbox></t:ToRecipients></t:Message></m:Items></m:CreateItem></soap:Body> 
    </soap:Envelope> 
</Trace> 

14/10/2012 01:13:48 م org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme 
    INFO: NTLM authentication scheme selected 
    <Trace Tag="EwsResponseHttpHeaders" Tid="1" Time="2012-10-14 11:13:48Z"> 
    200 text/xml; charset=utf-8 
    X-AspNet-Version : 2.0.50727 
    X-EwsPerformanceData : RpcC=3;RpcL=15;LdapC=0;LdapL=0; 
    Persistent-Auth : true 
    Date : Sun, 14 Oct 2012 11:13:48 GMT 
    Vary : Accept-Encoding 
    Transfer-Encoding : chunked 
    Content-Encoding : gzip 
    Content-Type : text/xml; charset=utf-8 
    X-Powered-By : ASP.NET 
    Server : Microsoft-IIS/7.5 
    Cache-Control : private 
</Trace> 

<Trace Tag="EwsResponse" Tid="1" Time="2012-10-14 11:13:48Z"> 
    <?xml version="1.0" encoding="utf-8"?> 
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Header><h:ServerVersionInfo MajorVersion="14" MinorVersion="1" MajorBuildNumber="218" MinorBuildNumber="14" Version="Exchange2010_SP1" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/></s:Header> 
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><m:CreateItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><m:ResponseMessages><m:CreateItemResponseMessage ResponseClass="Success"><m:ResponseCode>NoError</m:ResponseCode><m:Items/></m:CreateItemResponseMessage></m:ResponseMessages></m:CreateItemResponse></s:Body> 
    </s:Envelope> 
</Trace> 

請告知如何解決這個問題。

回答

0

交換服務器作出響應,一切都OK:

<?xml version="1.0" encoding="utf-8"?> 
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Header> 
    <h:ServerVersionInfo MajorVersion="14" MinorVersion="1" MajorBuildNumber="218" MinorBuildNumber="14" Version="Exchange2010_SP1" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/> 
    </s:Header> 
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <m:CreateItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"> 
     <m:ResponseMessages> 
     <m:CreateItemResponseMessage ResponseClass="Success"> 
      <m:ResponseCode>NoError</m:ResponseCode> 
      <m:Items/> 
     </m:CreateItemResponseMessage> 
     </m:ResponseMessages> 
    </m:CreateItemResponse> 
    </s:Body> 
</s:Envelope> 

您應該檢查在Exchange端,或詢問發生了什麼事情(比如一些垃圾郵件過濾或任何其他人)您的Exchange服務器管理員,因爲從代碼角度和SOAP請求/響應的角度來看,沒有什麼錯誤。

+0

您能否告訴我在交換服務器中檢查垃圾郵件過濾的位置? –

0
  <t:Message> 
      <t:Subject>Hello world!</t:Subject> 
      <t:Body BodyType="HTML">Sent using the EWS Managed API.</t:Body> 
      <t:ToRecipients> 
       <t:Mailbox> 
       <t:EmailAddress>[email protected]</t:EmailAddress> 
       </t:Mailbox> 
      </t:ToRecipients> 
      </t:Message> 

請檢查[email protected]的收件箱或交談Exchange管理員看郵件隊列,過濾器,許多其他的事情等可能來自何處停止電子郵件。 您的發佈代碼沒有錯。