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


    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:

    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");


    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

    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 [],
    >,250-SIZE 10485760,
    >,250 CHUNKING,
    <,AUTH gssapi,
    >,334 <authentication response>,
    >,334 <authentication response>,
    *,,Inbound Negotiate failed because of IllegalMessage
    >,535 5.7.3 Authentication unsuccessful,

    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

    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.


  • Akash Blogging......

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


    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/">
    <t:RequestServerVersion Version="Exchange2010" />
    <t:DistinguishedFolderId Id="inbox" />

    Below is the Response we got:
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <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: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:SubscribeResponseMessage ResponseClass="Error">
    <m:MessageText>The mailbox database is temporarily unavailable.</m:MessageText>

    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!


  • Akash Blogging......

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


    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)
    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)

    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.


    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


  • Akash Blogging......

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


    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:


    <?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/">
         <t:RequestServerVersion Version="Exchange2010" />

    <?xml version="1.0" encoding="utf-8"?>
     <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
         <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: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:ExpandDLResponseMessage ResponseClass="Success">
               <m:DLExpansion TotalItemsInView="0" IncludesLastItemInRange="true" />

    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.


    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.


  • Akash Blogging......

    Office 365 - Getting Started!


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

    Exchange Online Overview

    Developing Messaging Solutions for Exchange Online

    Exchange Online Technical Articles

    Office 365 Developer Training Course


Page 1 of 1 (5 items)