none
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 @mycompany.com), 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  @mycompany.com). 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.

    Thanks,

     

     

    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.

    Cheers
    Glen

    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 xxx@mycompany.com or xxx@mycompany.com [xxx@mycompany.com], 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 xxx@vendorname.com). Thank you very much for your help in advance.

    ExchangeWebServices.

    ExchangeServiceBinding esb = new ExchangeWebServices.ExchangeServiceBinding();

    esb.Url = sEWS_URL;

    esb.Credentials = nc;

     

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

    ExchangeWebServices.

    FindItemType findItemRequest = new ExchangeWebServices.FindItemType();

    findItemRequest.Traversal = ExchangeWebServices.

    ItemQueryTraversalType.Shallow;

     

    // Define which item properties are returned in the response

    ExchangeWebServices.

    ItemResponseShapeType itemProperties = new ExchangeWebServices.ItemResponseShapeType();

    itemProperties.BaseShape = ExchangeWebServices.

    DefaultShapeNamesType.AllProperties;

    findItemRequest.ItemShape = itemProperties;

     

    // Identify which folders to search to find items

    ExchangeWebServices.

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

    folderIDArray[0] =

    new ExchangeWebServices.DistinguishedFolderIdType();

    folderIDArray[0].Id = ExchangeWebServices.

    DistinguishedFolderIdNameType.inbox;

     

    // Add folders to request

    findItemRequest.ParentFolderIds = folderIDArray;

     

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

    ExchangeWebServices.

    RestrictionType restriction = new ExchangeWebServices.RestrictionType();

    ExchangeWebServices.

    IsEqualToType isEqualTo = new ExchangeWebServices.IsEqualToType();

    ExchangeWebServices.

    PathToUnindexedFieldType pathToFieldType = new ExchangeWebServices.PathToUnindexedFieldType();

    pathToFieldType.FieldURI = ExchangeWebServices.

    UnindexedFieldURIType.messageFrom;

    ExchangeWebServices.

    FieldURIOrConstantType constantType = new ExchangeWebServices.FieldURIOrConstantType();

    ExchangeWebServices.

    ConstantValueType constantValueType = new ExchangeWebServices.ConstantValueType();

    constantValueType.Value = Dts.Variables[

    "EmailSender"].Value.ToString();

     

    constantType.Item = constantValueType;

    isEqualTo.Item = pathToFieldType;

    isEqualTo.FieldURIOrConstant = constantType;

    restriction.Item = isEqualTo;

    findItemRequest.Restriction = restriction;

     

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

    Dts.Log(

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

     

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

    ExchangeWebServices.

    FindItemResponseType findItemResponse = esb.FindItem(findItemRequest);

    Dts.Log(

    "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.

    eg

          ResolveNamesType rnType = new ResolveNamesType();
          rnType.ReturnFullContactData = false;
          rnType.SearchScope = ResolveNamesSearchScopeType.ActiveDirectory;
          rnType.UnresolvedEntry = "user@domaintosearch.com";
    
          ResolveNamesResponseType rnResponse = esb.ResolveNames(rnType);
          ResolutionType rt = ((ResolveNamesResponseMessageType)rnResponse.ResponseMessages.Items[0]).ResolutionSet.Resolution[0];
          Console.WriteLine(rt.Mailbox.EmailAddress);

    Cheers
    Glen

    • 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 firstname.lastname@mycommany.com & firstinitial.lastname@mycompany.com. I didn't expect it comes back empty with the resolve name call response.

    Thanks,

    Hongmei

    Monday, January 3, 2011 10:22 PM
  • I would suggest you try to do some testing with the EWSeditor http://code.msdn.microsoft.com/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.

    Cheers
    Glen

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