June, 2011

  • Akash Blogging......

    Error: “Object reference not set to an instance of an object” when sending out mails using System.Net.Mail via Exchange 2007

    • 0 Comments

    This was a fun issue to work on! Some background, the customer was using System.Net.Mail to send out mails via Exchange 2007 using port 25 and port 587, all was working fine and then some updates were installed and he was no longer able to send out mails via port 587. He started to get the following exception:

    Exception:
    Object reference not set to an instance of an object.
    System.Net Error: at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
       at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
       at System.Net.Mail.SmtpClient.GetConnection()
       at System.Net.Mail.SmtpClient.Send(MailMessage message)

    The code was very simple:

    static void Main(string[] args)
    {
    SmtpClient _client = new SmtpClient();

    using (MailMessage _message = new MailMessage())
    {
    _message.Subject = "Test message";
    _message.Body = "Test message";

    _message.From = new MailAddress("support@xyz.com");
    _message.To.Add("akashb@xyz.com");

    _client.Send(_message);
    }
    }

    The host, port and the credentials were being picked up from the App.Config:

    <network host="EX-01.xyz.COM" port="587" userName="support@xyz.com" password="Password"/>

    What we were also told was that if in the code the SmtpClient.TargetName Property was set to blank then everything worked fine! What is this property? This property gets or sets the Service Provider Name (SPN) to use for authentication when using extended protection.

    We made sure we have the exact same setting on the Exchange 2007 Receive Connectors, updated the client with all the updates that were installed in the customer’s environment but we initially could not reproduce the issue. It did not matter if we set the TargetName to blank or not. We finally did reproduce the issue after I put the client machine where the code was running in the same domain as the Exchange Server and then setting the TargetName to blank did matter. Now the next step was to find out the update that caused the code to fail. We did get a hint from the SmtpClient.TargetName property and started to look for the patch that could cause the issue.

    Luckily, the search did not last long and we were able to identify the patch that caused the failure!

    Description of the rollup update for the .NET Framework 3.5 Service Pack 1 and the .NET Framework 2.0 Service Pack 2 on Windows XP and on Windows Server 2003 (976765 and 980773): June 8, 2010
    http://support.microsoft.com/kb/982167

    This updates the NLC on the system to support Extended Protection. When we uninstalling the update for KB 980773 from the system the code started to work. But now we had a few questions that we needed answer for:

    1)Is there something wrong with Exchange 2007?
    2)Does Exchange 2007 not understand the request for Authentication?
    3)Why does it still work with port 25 and fails only with port 587?

    We then decide to take a verbose log on the Exchange Receive connector and below is what we find:

    >,"220 EX-01.internal.xyz.com Microsoft ESMTP MAIL Service ready at Mon, 15 May 2011 08:59:37 -0500",
    <,EHLO akashb,
    >,250-EX-01.internal.xyz.com Hello [192.168.111.111],
    >,250-SIZE 10485760,
    >,250-PIPELINING,
    >,250-DSN,
    >,250-ENHANCEDSTATUSCODES,
    >,250-STARTTLS,
    >,250-AUTH GSSAPI NTLM LOGIN,
    >,250-8BITMIME,
    >,250-BINARYMIME,
    >,250 CHUNKING,
    <,AUTH gssapi,
    >,334 <authentication response>,
    >,334 <authentication response>,
    *,,Inbound Negotiate failed because of IllegalMessage
    >,535 5.7.3 Authentication unsuccessful,
    -,,Remote

    Looking at the verbose log it looks like Exchange does not understand the message, but why?

    Firstly the OS needs to be configured to support Extended Protection and secondly, support for Extended protection was introduced in Exchange 2007 SP 3. The best would be to have Exchange 2007 SP 3 RU 3 v2 installed. In this case it turns out that neither the customer nor I had Exchange 2007 SP 3 RU 3 v2. Make sure you have your SPN’s right. The below article talks about Extended Protection.

    Extended Protection for Authentication
    http://support.microsoft.com/kb/968389

    After Exchange 2007 SP 3 RU 3 v2 is installed you get a new property “ExtendedProtectionPolicy” for the Receive connector. You can then use the Set-ReceiveConnector  cmd-let and set the value for ExtendedProtectionPolicy to “Allow”. This also requires that RequireTLS is set to true on the connector and you must also set EnableSsl = true in the .Net code. So this answers the questions 1 & 2.

    Now for the question 3, why does it still work with port 25 and fails only with port 587?

    That was easy, the answer lies in EHLO. The Default receive connector (Port 25) did not have GSSAPI enabled and hence it was defaulting to NTLM(which works) instead using Negotiate. In the failing case, Negotiate was used with Extended protection, Exchange did not return the expected data and hence the error.

    -Enjoy

  • Akash Blogging......

    Pull Subscription request fails with error “The Mailbox database is temporarily unavailable” on Exchange 2010

    • 0 Comments

    This is the first time I ran into this issue with Exchange Web Services while sending out a Pull Subscription request! The confusing part was that apart from the subscribe request everything else was working as expected. We could connect to the mailbox using EWS Editor, browse the Inbox and other folders, Delete Items and so on…

    Below is the Request that was sent out:

    <?xml version="1.0" encoding="utf-8"?>
    <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" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
    <t:RequestServerVersion Version="Exchange2010" />
    </soap:Header>
    <soap:Body>
    <m:Subscribe>
    <m:PullSubscriptionRequest>
    <t:FolderIds>
    <t:DistinguishedFolderId Id="inbox" />
    </t:FolderIds>
    <t:EventTypes>
    <t:EventType>CopiedEvent</t:EventType>
    <t:EventType>CreatedEvent</t:EventType>
    <t:EventType>DeletedEvent</t:EventType>
    <t:EventType>ModifiedEvent</t:EventType>
    <t:EventType>MovedEvent</t:EventType>
    <t:EventType>NewMailEvent</t:EventType>
    </t:EventTypes>
    <t:Timeout>90</t:Timeout>
    </m:PullSubscriptionRequest>
    </m:Subscribe>
    </soap:Body>
    </soap:Envelope>

    Below is the Response we got:
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
    <h:ServerVersionInfo MajorVersion="14" MinorVersion="1" MajorBuildNumber="289" MinorBuildNumber="6" 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:SubscribeResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
    <m:ResponseMessages>
    <m:SubscribeResponseMessage ResponseClass="Error">
    <m:MessageText>The mailbox database is temporarily unavailable.</m:MessageText>
    <m:ResponseCode>ErrorMailboxStoreUnavailable</m:ResponseCode>
    <m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
    </m:SubscribeResponseMessage>
    </m:ResponseMessages>
    </m:SubscribeResponse>
    </s:Body>
    </s:Envelope>

    Looking at the ETL trace it was found that the underlying error was MAPI_E_NETWORK_ERROR (0x80040115) and we also got to the function that was failing. This helped in searching the Source Code for Exchange 2010, the intent was to find out if there was a way we could reproduce a similar error using the Exchange Management Shell. Luckily we discovered that Move-Mailbox cmd-let would also do something similar!  We discovered that the customer was unable to move mailboxes from one database to another on the same Mailbox Server and was getting the error MapiExceptionNetworkError: Unable to make connection to the server. (hr=0x800004005, ec=2423). Which server are we taking about?

    In this case it turns out that the CAS was not able to contact the Mailbox Server via NetBIOS name. Pinging the Mailbox with the NetBIOS name failed! Pinging the Mailbox with the FQDN worked! What was done to fix the problem?

    In this case a DNS suffix was added (DNS tab in the Advanced TCP/IP Settings) and now pinging the Mailbox with the NetBIOS name WORKED! Did the Move-Mailbox work? YES! Did the Subscribe Request work? YES!

    Enjoy!

  • Akash Blogging......

    Saving during send breaks relation between sent item and Voting responses in Outlook 2010–Updated

    • 0 Comments

    Do you use the voting feature in Outlook 2010? Do you “Save” the item in the Application_ItemSend event? Does everything work as expected?

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Item.Save
    End Sub

    I don’t think so. If you have not yet noticed, you loose the ability to track the voting responses that you have received. It also breaks the relationship between the Read Receipt(if you have requested one) and the sent mail message.

    We now have a hotfix that addresses this issue and it can now we download from:

    Description of the Outlook 2010 hotfix package (outlook-x-none)
    http://support.microsoft.com/kb/2547227

    However we have a scenario where this is still broken! If the user right clicks on a file and does a Send To – Mail Recipient and then adds the voting options, we loose the ability to track voting responses. We have identified the problem and the fix is in progress and should be out soon.

    Note: If the mail item is not saved OR you do not hook into the Application_ItemSend then don’t worry, everything will work as expected.

    Update:

    What we found out was that the Voting Response tracking was still broken when the user Right clicks on an file on the desktop/Hard drive and select "Send To" -> Mail Recipient and then added the voting options to the message. Fortunately this issue has also been resolved in the July 11th update.

    Description of the Outlook 2010 hotfix package (Outlook-x-none.msp): July 11, 2011
    http://support.microsoft.com/kb/2544027

    Enjoy!

  • Akash Blogging......

    ExpandGroup method returns no results for Dynamic Distribution Group in Exchange 2010

    • 5 Comments

    Strange but TRUE! This work in Exchange 2007 but does not in Exchange 2010. Below is the request and response that I get from a Exchange 2010 server for the ExpandGroup Exchange Web Services call:

    Request:

    <?xml version="1.0" encoding="utf-8"?>
     <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" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
       <soap:Header>
         <t:RequestServerVersion Version="Exchange2010" />
       </soap:Header>
       <soap:Body>
         <m:ExpandDL>
           <m:Mailbox>
             <t:EmailAddress>TestDDL@bhargava.com</t:EmailAddress>
           </m:Mailbox>
         </m:ExpandDL>
       </soap:Body>
     </soap:Envelope>

    Response:
    <?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="269" MinorBuildNumber="0" 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:ExpandDLResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
           <m:ResponseMessages>
             <m:ExpandDLResponseMessage ResponseClass="Success">
               <m:ResponseCode>NoError</m:ResponseCode>
               <m:DLExpansion TotalItemsInView="0" IncludesLastItemInRange="true" />
             </m:ExpandDLResponseMessage>
           </m:ResponseMessages>
         </m:ExpandDLResponse>
       </s:Body>
     </s:Envelope>

    In this case the TestDDL group had members but we got no results. It turns out that this broke as a result of a change trying to synchronize behavior between various Mail Clients. Fortunately, we have decided to fix this and the fix should be available in one of the upcoming Rollup Updates for Exchange 2010 Service Pack 1.

    The only workaround I know is of using LDAP to get the membership of a Dynamic Distribution Group if it fits your requirements.

    Update:

    This issue has been fixed in Exchange 2010 SP 1 RU 5. Exchange 2010 SP 1 RU 5 should be available in August 2011.Unfortunately this has been pushed to Exchange 2010 SP 1 RU 6. However, in case you need an Interim Update for SP 1 RU 4 OR RU 5 when it becomes available, open up a Service Request with Microsoft Support to obtain one.

    Enjoy!

  • Akash Blogging......

    Office 365 - Getting Started!

    • 0 Comments

    Below are a few articles that will help you get started with developing solution for Office 365

    Exchange Online Overview
    http://msdn.microsoft.com/en-us/Office365TrainingCourse_1V_3

    Developing Messaging Solutions for Exchange Online
    http://msdn.microsoft.com/en-us/office365trainingcourse_session-10_unit

    Exchange Online Technical Articles
    http://msdn.microsoft.com/en-us/library/gg193994(EXCHG.140).aspx

    Office 365 Developer Training Course
    http://msdn.microsoft.com/en-us/Office365TrainingCourse

    Enjoy!

Page 1 of 1 (5 items)