Laden...

WebDav Error 409 Conflict (Email Senden)

Erstellt von hergla vor 16 Jahren Letzter Beitrag vor 16 Jahren 1.884 Views
H
hergla Themenstarter:in
10 Beiträge seit 2007
vor 16 Jahren
WebDav Error 409 Conflict (Email Senden)

Hallo,

Ich habe ein Problem mit WebDav .
Ich benutze WebDav um eine Email aus einer ASP.NET Anwendung zu senden.
System : Windows Server 2003 , Exchange Server 2003 mit Active Directory.

Das ist mein Code :

using System;
using System.Net;
using System.IO;
using System.Text;

namespace ExchangeSDK.Snippets.CSharp
{
   class SendingMessageWebDAV
   {
      [STAThread]
      static void Main(string[] args)
      {
         System.Net.HttpWebRequest PUTRequest;
         System.Net.WebResponse PUTResponse;
         System.Net.HttpWebRequest MOVERequest;
         System.Net.WebResponse MOVEResponse;
         System.Net.CredentialCache MyCredentialCache;
         string strMailboxURI = "";
         string strSubURI = "";
         string strTempURI = "";
         string strServer = "ServerName";
         string strPassword = "!Password";
         string strDomain = "Domain";
         string strAlias = "SenderAlias";
         string strTo = "recipient@example.com";
         string strSubject = "WebDAV message test.";
         string strText = "This message was sent using WebDAV.";
         string strBody = "";
         byte[] bytes = null;
         System.IO.Stream PUTRequestStream = null;

         try
         {
            // Build the mailbox URI.
            strMailboxURI = "http://" + strServer + "/exchange/" + strAlias;

            // Build the submission URI for the message.  If Secure
            // Sockets Layer (SSL) is set up on the server, use
            // "https://" instead of "http://".
            strSubURI = "http://" + strServer + "/exchange/" + strAlias
                      + "/##DavMailSubmissionURI##/";

            // Build the temporary URI for the message. If SSL is set
            // up on the server, use "https://" instead of "http://".
            strTempURI = "http://" + strServer + "/exchange/" + strAlias
                       + "/drafts/" + strSubject + ".eml";

            // Construct the RFC 822 formatted body of the PUT request.
            // Note: If the From: header is included here,
            // the MOVE method request will return a
            // 403 (Forbidden) status. The From address will
            // be generated by the Exchange server.
            strBody = "To: " + strTo + "\n" +
            "Subject: " + strSubject + "\n" +
            "Date: " + System.DateTime.Now +
            "X-Mailer: test mailer" + "\n" +
            "MIME-Version: 1.0" + "\n" +
            "Content-Type: text/plain;" + "\n" +
            "Charset = \"iso-8859-1\"" + "\n" +
            "Content-Transfer-Encoding: 7bit" + "\n" +
            "\n" + strText;

            // Create a new CredentialCache object and fill it with the network
            // credentials required to access the server.
            MyCredentialCache = new System.Net.CredentialCache();
            MyCredentialCache.Add( new System.Uri(strMailboxURI),
              "NTLM",
               new System.Net.NetworkCredential(strAlias, strPassword, strDomain)
               );

            // Create the HttpWebRequest object.
            PUTRequest = (System.Net.HttpWebRequest)HttpWebRequest.Create(strTempURI);

            // Add the network credentials to the request.
            PUTRequest.Credentials = MyCredentialCache;

            // Specify the PUT method.
            PUTRequest.Method = "PUT";

            // Encode the body using UTF-8.
            bytes = Encoding.UTF8.GetBytes((string)strBody);

            // Set the content header length.  This must be
            // done before writing data to the request stream.
            PUTRequest.ContentLength = bytes.Length;

            // Get a reference to the request stream.
            PUTRequestStream = PUTRequest.GetRequestStream();

            // Write the message body to the request stream.
            PUTRequestStream.Write(bytes, 0, bytes.Length);

            // Close the Stream object to release the connection
            // for further use.
            PUTRequestStream.Close();

            // Set the Content-Type header to the RFC 822 message format.
            PUTRequest.ContentType = "message/rfc822";

            // PUT the message in the Drafts folder of the
            // sender's mailbox.
            PUTResponse = (System.Net.HttpWebResponse)PUTRequest.GetResponse();

            // Create the HttpWebRequest object.
            MOVERequest = (System.Net.HttpWebRequest)HttpWebRequest.Create(strTempURI);

            // Add the network credentials to the request.
            MOVERequest.Credentials = MyCredentialCache;

            // Specify the MOVE method.
            MOVERequest.Method = "MOVE";

            // Set the Destination header to the
            // mail submission URI.
            MOVERequest.Headers.Add("Destination", strSubURI);

            // Send the message by moving it from the Drafts folder of the
            // sender's mailbox to the mail submission URI.
            MOVEResponse = (System.Net.HttpWebResponse)MOVERequest.GetResponse();

            Console.WriteLine("Message successfully sent.");

            // Clean up.
            PUTResponse.Close();
            MOVEResponse.Close();

         }
         catch(Exception ex)
         {
            // Catch any exceptions. Any error codes from the PUT
            // or MOVE method requests on the server will be caught
            // here, also.
            Console.WriteLine(ex.Message);
         }
      }
   }
}

++
Problem : Das funktionniert , also es werden Emails geschickt ABER NUR MIT BESTIMMTE USER , (Mit dem Administrator nicht !), sonst bekomme Ich die Fehlermeldung :++**:::

Ich habe es auch aus einer Konsolenanwendung probiert, und es klappt nur mit den gleichen Usern wie in der Asp.Net Anwendung.

ich bin dankbar für jede Hilfe.

Danke im voraus.

3.728 Beiträge seit 2005
vor 16 Jahren
Benutzer

Du kannst über ein Benutzerkonto E-Mails über Exchange Server nur versenden, wenn dieses Benutzerkonto auch ein Exchange-Postfach (Engl. Mailbox) hat. Nicht jeder Benutzer im Active Directory hat automatisch ein Exchange-Postfach. Besonders bei Benutzern, wie dem Administrator, deren Active Directory Konten schon da waren, bevor Exchange Server überhaupt installiert wurde, ist es sehr wahrscheinlich, dass kein Exchange-Postfach eingerichtet wurde. Du kannst das mit dem Dienstprogramm "Active Directory Benutzer und Computer" auf dem Exchange Server Computer überprüfen und ggf. ein Postfach für den Administrator anlegen.

Oder möchtest Du von einem anderen Postfach aus E-Mails mit dem Absender "Administrator" versenden? Dafür musst Du "Send As" Berechtigungen auf das entsprechende Postfach besitzen.

H
hergla Themenstarter:in
10 Beiträge seit 2007
vor 16 Jahren

Hallo ,
Danke für die Antwort.
ich habe die problemursache herausgefunden : Es liegt an der Sprache des Systems !!!
Als ich das System installiert habe, war die Sprache Englisch, also Windows sever 2003 Englisch..
Damals könnte ich die postfach Adressen auf exchange z.B mit http://myServer/exchange/MyAlias/Inbox ansprechen, als ich dann die Sprache des Systems auf Deutsch gesetzt habe, hat Windows die neue Adressen mit deutsche Begriffe umbenannt : http://myServer/exchange/MyAlias/Inbox heisst für die neu eingefügte Benutzer und nur für die : http://myServer/exchange/MyAlias/Posteingang !!!
daher kommt die fehlermeldung (409) Conflict

Ich glaube das ist ein Fehler das microsoft nicht ignorieren soll....

Danke.