Exchange web service (EWS) can not pick up e-mail with sender inside our domain (or Active directory) RRS feed

  • Question

  • I had an SSIS package (with SQL 2008) used the custom scripts (c#), which use the EWS (as web refrefence) to check the e-mail (binding the sendfrom) to one of our svc account and then find the attachment and import that to database daily. It all working fine for month, but when our company finally shutdown the old exchange server, the new one is exchange 2007. I had problem to pick up the e-mail, I can see the e-mail in the webmail (owa) or outlook, but the webservice call just report nothing back (no item found).

    I try to ask the vendor to send e-mail with outside domain address (not anything like, it seems that did the trick. But I back to this problem again due to now we had another vendor use the profile email (with our company address) to send file daily, we try to automate this process now. I had the SSIS working when testing, but once switch it to the inter-compnay e-mail address, it just can not pick up any. Unfortunately, this time, there is no way to changethe e-mail sender to something does not exists at all, so I can not use the same workaround.

    In the meantime, I did notice when I test month ago when I had problem first, that if I send the e-mail to this account with outlook client, the e-mail show up the sender as "last name,firstname" ==> EWS can pick up the e-mail accordingly. But if I use the auto-forward rule, the sender on the e-mail is not in that format ==> EWS just cannot see it at all. I think it's something missing between the Active directory and exchange, but I'm not a system admin anyway, so have no clue.

    And all the time, it works fine with sender from outside our domain (not this is is realy odd. And out exhcange team keeps telling me that everythign is right on their server, but apparently, the web service response back just not right, I can see the item just sit there in the inbox. So if anyone can give ma a hint, I would really apperciated it.




    Wednesday, December 22, 2010 9:55 PM

All replies

  • It sounds like your restriction or search filter is failing ? what does this look like ?

    The one thing to keep in mind is that if a sender of the message is Internal (eg exists in the GAL) then Exchange will always rewrite the sender information in the message when it delivers the message based on what is the GAL. In generally this isn't a problem but for example if your filter is based on the secondary proxy address of the sender you will never see that the message was sent from that particular address.  It can be useful to look at the message with Mapi editor like OutlookSpy of MFCMapi this allows you both to view the recipient table of the message as well as all the sender properties.

    Its unlikely that it will be a Exchange Server configuration issue so you will most likely need need to adjust your restriction.


    Thursday, December 23, 2010 1:59 AM
  • Here is my code for EWS and the restriction (sendfrom). I had try to configure the sendfrom in or [], the later one is exactly what I see in the outlook client.  The same job runs ok for several month, when exchange server 2003 and exchange server 2007 coexists. But when they finally shutdown the exchange 2003, the job had problem to pick inside company address's e-mail. But it still working fine for all other vendor that use their e-mail as sender, that's send from outside our company (such as Thank you very much for your help in advance.


    ExchangeServiceBinding esb = new ExchangeWebServices.ExchangeServiceBinding();

    esb.Url = sEWS_URL;

    esb.Credentials = nc;


    //----------------------- main code ---------------


    FindItemType findItemRequest = new ExchangeWebServices.FindItemType();

    findItemRequest.Traversal = ExchangeWebServices.



    // Define which item properties are returned in the response


    ItemResponseShapeType itemProperties = new ExchangeWebServices.ItemResponseShapeType();

    itemProperties.BaseShape = ExchangeWebServices.


    findItemRequest.ItemShape = itemProperties;


    // Identify which folders to search to find items


    DistinguishedFolderIdType[] folderIDArray = new ExchangeWebServices.DistinguishedFolderIdType[1];

    folderIDArray[0] =

    new ExchangeWebServices.DistinguishedFolderIdType();

    folderIDArray[0].Id = ExchangeWebServices.



    // Add folders to request

    findItemRequest.ParentFolderIds = folderIDArray;


    //Create sendfrom restriction --------------------------


    RestrictionType restriction = new ExchangeWebServices.RestrictionType();


    IsEqualToType isEqualTo = new ExchangeWebServices.IsEqualToType();


    PathToUnindexedFieldType pathToFieldType = new ExchangeWebServices.PathToUnindexedFieldType();

    pathToFieldType.FieldURI = ExchangeWebServices.



    FieldURIOrConstantType constantType = new ExchangeWebServices.FieldURIOrConstantType();


    ConstantValueType constantValueType = new ExchangeWebServices.ConstantValueType();

    constantValueType.Value = Dts.Variables[



    constantType.Item = constantValueType;

    isEqualTo.Item = pathToFieldType;

    isEqualTo.FieldURIOrConstant = constantType;

    restriction.Item = isEqualTo;

    findItemRequest.Restriction = restriction;


    // ------------- GetAccessibilityObjectById the stream


    "Sending Get Items Request", 999, null);


    // ------------- Send the request and get the response


    FindItemResponseType findItemResponse = esb.FindItem(findItemRequest);


    "Received Response Get Items", 999, null);


    Thursday, December 23, 2010 2:26 PM
  • You need to make sure your allways searching using the primary SMTP address of the sender one way to be sure of this is if you detect that the address is internal use a resolveName operation to get the primary SMTP and then search on that which should allways work.


          ResolveNamesType rnType = new ResolveNamesType();
          rnType.ReturnFullContactData = false;
          rnType.SearchScope = ResolveNamesSearchScopeType.ActiveDirectory;
          rnType.UnresolvedEntry = "";
          ResolveNamesResponseType rnResponse = esb.ResolveNames(rnType);
          ResolutionType rt = ((ResolveNamesResponseMessageType)rnResponse.ResponseMessages.Items[0]).ResolutionSet.Resolution[0];


    • Proposed as answer by Falak Mahmood Wednesday, February 2, 2011 12:50 PM
    Friday, December 24, 2010 5:09 AM
  • Glen,

    Thank you very much for your help. I had been out of office several days and I try to check the email address as you mentioned above today. Unfortuntely, I get the error (NULL reference).

    System.NullReferenceException: Object reference not set to an instance of an object.

    It's for that line of code "ResolutionType rt = ((ResolveNamesResponseMessageType)rnResponse.ResponseMessages.Items[0]).ResolutionSet.Resolution[0];", that is, the search didn't return any for me. Is there anything wrong in our exchange server? I thought it should at least return 1 or 2, we usually have & I didn't expect it comes back empty with the resolve name call response.



    Monday, January 3, 2011 10:22 PM
  • I would suggest you try to do some testing with the EWSeditor this will allow you to test things like resolvename with various address and see what type of responses you get it will also allow you to test EWS outside of your own code base which may have some logic issues.


    • Proposed as answer by Falak Mahmood Wednesday, February 2, 2011 12:50 PM
    Tuesday, January 4, 2011 2:14 AM