OfficeDev / ews-java-api

A java client library to access Exchange web services. The API works against Office 365 Exchange Online as well as on premises Exchange.
MIT License
869 stars 560 forks source link

Bug sending email using Exchange 2007 #211

Open plunchete opened 9 years ago

plunchete commented 9 years ago

Hi there,

I'm using this library in production and we have a bunch of users with Exchange 2007. The problem is that when we try to send an email through their Exchange servers we get the following exception:

Caused by: microsoft.exchange.webservices.data.ServiceResponseException: An internal server error occurred. The operation failed.
at microsoft.exchange.webservices.data.ServiceResponse.internalThrowIfNecessary(ServiceResponse.java:268)
at microsoft.exchange.webservices.data.ServiceResponse.throwIfNecessary(ServiceResponse.java:256)
at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:155)
at microsoft.exchange.webservices.data.ExchangeService.internalCreateItems(ExchangeService.java:468)
at microsoft.exchange.webservices.data.ExchangeService.createItem(ExchangeService.java:539)
at microsoft.exchange.webservices.data.Item.internalCreate(Item.java:219)
at microsoft.exchange.webservices.data.EmailMessage.internalSend(EmailMessage.java:129)
at microsoft.exchange.webservices.data.EmailMessage.sendAndSaveCopy(EmailMessage.java:290)

I've checked with the users to see if the library was sending the message but failing getting a response but that is not the case. The message is stored in their drafts folder and never gets sent

ahaarrestad commented 9 years ago

Are you by any chance running your program using -ae on the commandline? If so, try to run without it and see what happens.

plunchete commented 9 years ago

Not sure what you mean, I'm running it on tomcat and as far as I know it doesn't have that option. Is there anything that I can do from code to know that?

ahaarrestad commented 9 years ago

you probably are running with -ae, because it looks like it's failing on an assert.

2015-02-11 20:01 GMT+01:00 Ignacio Andreu notifications@github.com:

Not sure what you mean, I'm running it on tomcat and as far as I know it doesn't have that option. Is there anything that I can do from code to know that?

— Reply to this email directly or view it on GitHub https://github.com/OfficeDev/ews-java-api/issues/211#issuecomment-73941653 .

serious6 commented 9 years ago

Don't think this is about assertions. There is no java.lang.AssertionError. The message indicates a server error. Maybe you can enable tracing of the request and the response to see what's happend and have this information attached to this issue. It may also be important which version of the API you are running.

plunchete commented 9 years ago

This is what I get if I enable the logs for HttpClient

2015/02/12 15:24:47:725 PST [DEBUG] HttpMethodDirector - Authenticating with NTLM <any realm>@domain.com:443
2015/02/12 15:24:47:725 PST [DEBUG] HttpMethodParams - Credential charset not configured, using HTTP element charset
2015/02/12 15:24:47:728 PST [DEBUG] header - >> "POST /ews/exchange.asmx HTTP/1.1[\r][\n]"
2015/02/12 15:24:47:728 PST [DEBUG] HttpMethodBase - Adding Host request header
2015/02/12 15:24:47:728 PST [DEBUG] header - >> "Content-type: text/xml; charset=utf-8[\r][\n]"
2015/02/12 15:24:47:728 PST [DEBUG] header - >> "User-Agent: ExchangeServicesClient/0.0.0.0[\r][\n]"
2015/02/12 15:24:47:728 PST [DEBUG] header - >> "Accept: text/xml[\r][\n]"
2015/02/12 15:24:47:728 PST [DEBUG] header - >> "Keep-Alive: 300[\r][\n]"
2015/02/12 15:24:47:728 PST [DEBUG] header - >> "Connection: Keep-Alive[\r][\n]"
2015/02/12 15:24:47:729 PST [DEBUG] header - >> "Accept-Encoding: gzip,deflate[\r][\n]"
2015/02/12 15:24:47:729 PST [DEBUG] header - >> "Content-Length: 1393[\r][\n]"
2015/02/12 15:24:47:729 PST [DEBUG] header - >> "Authorization: NTLM XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX[\r][\n]"
2015/02/12 15:24:47:729 PST [DEBUG] header - >> "Host: domain.com[\r][\n]"
2015/02/12 15:24:47:729 PST [DEBUG] header - >> "[\r][\n]"
2015/02/12 15:24:47:729 PST [DEBUG] content - >> "<?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="Exchange2007" /></soap:Header><soap:Body><m:CreateItem MessageDisposition="SendAndSaveCopy"><m:SavedItemFolderId><t:DistinguishedFolderId Id="sentitems" /></m:SavedItemFolderId><m:Items><t:Message><t:Subject>SUBJECT</t:Subject><t:Body BodyType="HTML">Test</t:Body><t:ExtendedProperty><t:ExtendedFieldURI DistinguishedPropertySetId="InternetHeaders" PropertyName="From" PropertyType="String" /><t:Value>YY@XX.com</t:Value></t:ExtendedProperty><t:ExtendedProperty><t:ExtendedFieldURI DistinguishedPropertySetId="InternetHeaders" PropertyName="To" PropertyType="String" /><t:Value>XX@YY.com</t:Value></t:ExtendedProperty><t:ExtendedProperty><t:ExtendedFieldURI DistinguishedPropertySetId="InternetHeaders" PropertyName="Subject" PropertyType="String" /><t:Value>SUBJECT</t:Value></t:ExtendedProperty><t:ToRecipients><t:Mailbox><t:EmailAddress>XX@YY.com</t:EmailAddress></t:Mailbox></t:ToRecipients></t:Message></m:Items></m:CreateItem></soap:Body></soap:Envelope>"
2015/02/12 15:24:47:729 PST [DEBUG] EntityEnclosingMethod - Request body sent
2015/02/12 15:24:47:829 PST [DEBUG] header - << "HTTP/1.1 200 OK[\r][\n]"
2015/02/12 15:24:47:829 PST [DEBUG] header - << "HTTP/1.1 200 OK[\r][\n]"
2015/02/12 15:24:47:829 PST [DEBUG] header - << "Date: Thu, 12 Feb 2015 23:24:47 GMT[\r][\n]"
2015/02/12 15:24:47:829 PST [DEBUG] header - << "Server: Microsoft-IIS/6.0[\r][\n]"
2015/02/12 15:24:47:829 PST [DEBUG] header - << "X-Powered-By: ASP.NET[\r][\n]"
2015/02/12 15:24:47:829 PST [DEBUG] header - << "X-AspNet-Version: 2.0.50727[\r][\n]"
2015/02/12 15:24:47:829 PST [DEBUG] header - << "Cache-Control: private, max-age=0[\r][\n]"
2015/02/12 15:24:47:829 PST [DEBUG] header - << "Content-Type: text/xml; charset=utf-8[\r][\n]"
2015/02/12 15:24:47:829 PST [DEBUG] header - << "Content-Length: 949[\r][\n]"
2015/02/12 15:24:47:830 PST [DEBUG] header - << "[\r][\n]"
2015/02/12 15:24:47:830 PST [DEBUG] content - << "<?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:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><t:ServerVersionInfo MajorVersion="8" MinorVersion="3" MajorBuildNumber="389" MinorBuildNumber="2" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" /></soap:Header><soap:Body><m:CreateItemResponse xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"><m:ResponseMessages><m:CreateItemResponseMessage ResponseClass="Error"><m:MessageText>An internal server error occurred. The operation failed.</m:MessageText><m:ResponseCode>ErrorInternalServerError</m:ResponseCode><m:DescriptiveLinkKey>0</m:DescriptiveLinkKey><m:Items /></m:CreateItemResponseMessage></m:ResponseMessages></m:CreateItemResponse></soap:Body></soap:Envelope>"
2015/02/12 15:24:47:832 PST [DEBUG] HttpMethodBase - Should NOT close connection in response to directive: Keep-Alive
2015/02/12 15:24:47:832 PST [DEBUG] HttpConnection - Releasing connection back to connection manager.
2015/02/12 15:24:47:832 PST [DEBUG] MultiThreadedHttpConnectionManager - Freeing connection, hostConfig=HostConfiguration[host=https://domain.com]
2015/02/12 15:24:47:832 PST [DEBUG] IdleConnectionHandler - Adding connection at: 1423783487832
2015/02/12 15:24:47:832 PST [DEBUG] MultiThreadedHttpConnectionManager - Notifying no-one, there are no waiting threads
microsoft.exchange.webservices.data.ServiceResponseException: An internal server error occurred. The operation failed.
    at microsoft.exchange.webservices.data.ServiceResponse.internalThrowIfNecessary(ServiceResponse.java:268)
    at microsoft.exchange.webservices.data.ServiceResponse.throwIfNecessary(ServiceResponse.java:256)
    at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:155)
    at microsoft.exchange.webservices.data.ExchangeService.internalCreateItems(ExchangeService.java:468)
    at microsoft.exchange.webservices.data.ExchangeService.createItem(ExchangeService.java:539)
    at microsoft.exchange.webservices.data.Item.internalCreate(Item.java:219)
    at microsoft.exchange.webservices.data.EmailMessage.internalSend(EmailMessage.java:129)
    at microsoft.exchange.webservices.data.EmailMessage.sendAndSaveCopy(EmailMessage.java:290)
    ... 2 more

I think I forgot to mention that we have 500+ exchanges and everything works in 2010 and 2013 but not in 2007 SP1 or 2007 SP2. Also, I've seen this happening in many different 2007 servers not only one so I don't think is a bug in the server but in the library.

I hope you guys can help me

plunchete commented 9 years ago

I actually just discovered that the problem is not on your library but in another library that I use as a bridge between your library and JavaMail.

Thank you for taking the time in looking into my issue :)

rjk commented 9 years ago

For anyone (like me) getting a similar error sending email through EWS, what was the underlying problem and solution?

plunchete commented 9 years ago

@rjk my problem was that I was including the same to address twice.

rjk commented 9 years ago

Great, thanks!

serious6 commented 9 years ago

Your comment indicates that the Problem has not Bern solved so far. Reopened for solving the issue which includes a to adress more than once.