none
Sending a Message (WebDAV) -- (440) Login Timeout RRS feed

  • Question

  • Hello all,

    I'm trying to interface with Exchange to send mail. I've copied the source supplied in the C# example at http://msdn.microsoft.com/en-us/library/aa563371.aspx and supplied it the address of our Exchange server, my Domain (NTLM) credentials, and ensure that I'm using https:// instead of http://.

    When I run the sample, which tries to send a test message with the above parameters, I get the following exception message: 

    System.Net.WebException: The remote server returned an error: (440) Login Timeout.
       at System.Net.HttpWebRequest.GetResponse()
       at MailTestApplication.MailTest.SendMail(String to) in C:\Documents and Settings...

    Here is the associated source code.

    1 using System;  
    2 using System.Collections.Generic;  
    3 using System.Linq;  
    4 using System.Text;  
    5 using System.Net.Mail;  
    6 using System.ComponentModel;  
    7 using System.Net;  
    8 using Microsoft.Office.Interop.Outlook;  
    9  
    10 namespace MailTestApplication  
    11 {  
    12     class MailTest  
    13     {  
    14         public void SendMail(string to)  
    15         {  
    16          System.Net.HttpWebRequest PUTRequest;  
    17          System.Net.WebResponse PUTResponse;  
    18          System.Net.HttpWebRequest MOVERequest;  
    19          System.Net.WebResponse MOVEResponse;  
    20          System.Net.CredentialCache MyCredentialCache;  
    21          string strMailboxURI = "";  
    22          string strSubURI = "";  
    23          string strTempURI = "";  
    24          string strServer = "mail.mycorp.com";  
    25          string strPassword = "mypassword";  
    26          string strDomain = "DOMAIN";  
    27          string strAlias = "brad.heller";  
    28          string strTo = "brad.heller@mycorp.com";  
    29          string strSubject = "WebDAV message test.";  
    30          string strText = "This message was sent using WebDAV.";  
    31          string strBody = "";  
    32          byte[] bytes = null;  
    33          System.IO.Stream PUTRequestStream = null;  
    34  
    35          try 
    36          {  
    37             // Build the mailbox URI.  
    38             strMailboxURI = "https://" + strServer + "/exchange/" + strAlias;  
    39  
    40             // Build the submission URI for the message.  If Secure  
    41             // Sockets Layer (SSL) is set up on the server, use  
    42             // "https://" instead of "http://".  
    43             strSubURI = "https://" + strServer + "/exchange/" + strAlias  
    44                       + "/##DavMailSubmissionURI##/";  
    45  
    46             // Build the temporary URI for the message. If SSL is set  
    47             // up on the server, use "https://" instead of "http://".  
    48             strTempURI = "https://" + strServer + "/exchange/" + strAlias  
    49                        + "/drafts/" + strSubject + ".eml";  
    50  
    51             // Construct the RFC 822 formatted body of the PUT request.  
    52             // Note: If the From: header is included here,  
    53             // the MOVE method request will return a  
    54             // 403 (Forbidden) status. The From address will  
    55             // be generated by the Exchange server.  
    56             strBody = "To: " + strTo + "\n" +  
    57             "Subject: " + strSubject + "\n" +  
    58             "Date: " + System.DateTime.Now +  
    59             "X-Mailer: test mailer" + "\n" +  
    60             "MIME-Version: 1.0" + "\n" +  
    61             "Content-Type: text/plain;" + "\n" +  
    62             "Charset = \"iso-8859-1\"" + "\n" +  
    63             "Content-Transfer-Encoding: 7bit" + "\n" +  
    64             "Keep-Alive: true\n"+  
    65             "\n" + strText;  
    66  
    67             // Create a new CredentialCache object and fill it with the network  
    68             // credentials required to access the server.  
    69             MyCredentialCache = new System.Net.CredentialCache();  
    70             MyCredentialCache.Add( new System.Uri(strMailboxURI), "NTLM"new System.Net.NetworkCredential(strAlias, strPassword, strDomain));  
    71  
    72             // Create the HttpWebRequest object.  
    73             PUTRequest = (System.Net.HttpWebRequest)HttpWebRequest.Create(strTempURI);  
    74  
    75             // Add the network credentials to the request.  
    76             PUTRequest.Credentials = MyCredentialCache;  
    77  
    78             // Specify the PUT method.  
    79             PUTRequest.Method = "PUT";  
    80  
    81             // Encode the body using UTF-8.  
    82             bytes = Encoding.UTF8.GetBytes((string)strBody);  
    83  
    84             // Set the content header length.  This must be  
    85             // done before writing data to the request stream.  
    86             PUTRequest.ContentLength = bytes.Length;  
    87  
    88             // Get a reference to the request stream.  
    89             PUTRequestStream = PUTRequest.GetRequestStream();  
    90  
    91             // Write the message body to the request stream.  
    92             PUTRequestStream.Write(bytes, 0, bytes.Length);  
    93  
    94             // Close the Stream object to release the connection  
    95             // for further use.  
    96             PUTRequestStream.Close();  
    97  
    98             // Set the Content-Type header to the RFC 822 message format.  
    99             PUTRequest.ContentType = "message/rfc822";  
    100  
    101             // PUT the message in the Drafts folder of the  
    102             // sender's mailbox.  
    103             PUTResponse = (System.Net.HttpWebResponse)PUTRequest.GetResponse();  
    104  
    105             // Create the HttpWebRequest object.  
    106             MOVERequest = (System.Net.HttpWebRequest)HttpWebRequest.Create(strTempURI);  
    107  
    108             // Add the network credentials to the request.  
    109             MOVERequest.Credentials = MyCredentialCache;  
    110  
    111             // Specify the MOVE method.  
    112             MOVERequest.Method = "MOVE";  
    113  
    114             // Set the Destination header to the  
    115             // mail submission URI.  
    116             MOVERequest.Headers.Add("Destination", strSubURI);  
    117  
    118             // Send the message by moving it from the Drafts folder of the  
    119             // sender's mailbox to the mail submission URI.  
    120             MOVEResponse = (System.Net.HttpWebResponse)MOVERequest.GetResponse();  
    121  
    122             Console.WriteLine("Message successfully sent.");  
    123  
    124             // Clean up.            PUTResponse.Close();  
    125             MOVEResponse.Close();  
    126  
    127          }  
    128          catch(System.Exception ex)  
    129          {  
    130             // Catch any exceptions. Any error codes from the PUT  
    131             // or MOVE method requests on the server will be caught  
    132             // here, also.  
    133             Console.WriteLine(ex.ToString());  
    134          }  
    135         }  
    136     }  
    137 }  
    138  

    Can anyone please provide a bit of guidance on what I'm doing wrong? Searchs only turn up issues with OWA.

    Thanks,
    Brad Heller
    Friday, December 5, 2008 8:25 PM

Answers

  • Hi Brad,

    Thank you for contacting us and your interest in Exchange development.  This forum is for discussion around the technical content of the Exchange Server Protocols documentation.  
     

    There is a very helpful community of Exchange developers on the Exchange Development forum that may be able to assist you with your solution. I suggest you post your question to the TechNet Forum » Exchange Server » Development.

    When posting to this forum please provide background information about your environment and proposed solution such as:

    • Exchange Server version.
    • Description of your Exchange and IIS topology.

    Providing this background information will better enable other developers to help you with your solution. Also feel free to answer other posts on the forum.


    Developer Consultant

    Friday, December 5, 2008 10:43 PM
    Moderator