Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Exchange WebDAV保存到草稿不可编辑_C#_Webdav_Exchange Server 2003 - Fatal编程技术网

C# Exchange WebDAV保存到草稿不可编辑

C# Exchange WebDAV保存到草稿不可编辑,c#,webdav,exchange-server-2003,C#,Webdav,Exchange Server 2003,我使用以下代码将邮件保存到Exchange WEBDAV草稿文件夹。它会保存邮件,但如果在Outlook中打开,则“发送”按钮将被禁用,并且邮件为只读。请帮我找到我在这段代码中遗漏了什么 谢谢 布万 strBody=“To:”+strTo+“\n”+ 主题:“+(string.IsNullOrEmpty(message.Subject)?”“:message.Subject)+”\n+ 日期:“+System.DateTime.Now+”\n+ “X-Mailer:测试邮件程序”+“\n”+ M

我使用以下代码将邮件保存到Exchange WEBDAV草稿文件夹。它会保存邮件,但如果在Outlook中打开,则“发送”按钮将被禁用,并且邮件为只读。请帮我找到我在这段代码中遗漏了什么

谢谢 布万

strBody=“To:”+strTo+“\n”+
主题:“+(string.IsNullOrEmpty(message.Subject)?”“:message.Subject)+”\n+
日期:“+System.DateTime.Now+”\n+
“X-Mailer:测试邮件程序”+“\n”+
MIME版本:1.0“+”\n+
内容类型:text/html;“+”\n+
“字符集=\“iso-8859-1\”“+”\n”+
内容传输编码:8位“+”\n+
“\n”+(string.IsNullOrEmpty(message.HtmlBody)?”“:message.HtmlBody.Replace(“,”).Replace(“,”);
//创建HttpWebRequest对象。
PUTRequest=(System.Net.HttpWebRequest)HttpWebRequest.Create(tgtUri);
//将网络凭据添加到请求中。
//使用服务的默认凭据访问服务器。
PUTRequest.Credentials=cred;
//指定PUT方法。
PUTRequest.Method=“PUT”//支撑块
//使用UTF-8对身体进行编码。
byte[]bytes=Encoding.UTF8.GetBytes((字符串)strBody);
//设置内容标题长度。这一定是
//在将数据写入请求流之前完成。
PUTRequest.ContentLength=字节.Length;
//获取对请求流的引用。
PUTRequestStream=PUTRequest.GetRequestStream();
//将消息正文写入请求流。
PUTRequestStream.Write(字节,0,字节.长度);
//关闭流对象以释放连接
//供进一步使用。
PUTRequestStream.Close();
//将内容类型标头设置为RFC 822消息格式。
PUTRequest.ContentType=“message/rfc822”;
//将邮件放入
//发件人的邮箱。
PUTResponse=(System.Net.HttpWebResponse)PUTRequest.GetResponse();
如果(message.Attachments!=null)
{
//做支撑补丁
System.Net.HttpWebRequest PROPPATCHRequest;
System.Net.WebResponse-propatchresponse;
System.IO.Stream PROPPATCHRequestStream=null;
字符串strxml=“”+
"" +
"" +
"" +
“假”+
"" +
""
+ ""
+ ""
+ "" 
+ "";
PROPPATCHRequest=(System.Net.HttpWebRequest)HttpWebRequest.Create(tgtUri);
PROPPATCHRequest.Credentials=cred;
PROPPATCHRequest.Headers.Set(“Translate”,“f”);
PROPPATCHRequest.ContentType=“text/xml”;
PROPPATCHRequest.ContentLength=strxml.Length;
PROPPATCHRequest.Method=“PROPPATCH”;
byte[]PROPPATCHbytes=Encoding.UTF8.GetBytes(strxml);
PROPPATCHRequest.ContentLength=PROPPATCHbytes.Length;
PROPPATCHRequestStream=PROPPATCHRequest.GetRequestStream();
写入(PROPPATCHbytes,0,PROPPATCHbytes.Length);
PROPPATCHRequestStream.Close();
PROPPATCHResponse=(System.Net.HttpWebResponse)PROPPATCHRequest.GetResponse();
foreach(message.Attachments中的KeyValuePair附件)
{
System.IO.Stream PUTAttachRequestStream=null;
System.Net.HttpWebRequest PUTAttachRequest;
System.Net.WebResponse PutatchResponse;
//附加文件:可以将其放入循环中以附加多个文件。
字符串文件名=attachment.Key;/@“2842498_7948002035296_Label1.pdf”;
字符串attachURI=tgtUri+“/”+文件名;
PUTAttachRequest=(System.Net.HttpWebRequest)HttpWebRequest.Create(attachURI);
PUTAttachRequest.Credentials=cred;
PUTAttachRequest.Method=“PUT”;
PUTAttachRequest.ContentLength=attachment.Value.Length;//binaryData.Length;
PUTAttachRequestStream=PUTAttachRequest.GetRequestStream();
写入(attachment.Value,0,attachment.Value.Length);/(binaryData,0,binaryData.Length);
PUTAttachRequestStream.Close();
PuttachResponse=(System.Net.HttpWebResponse)PuttachRequest.GetResponse();
PUTAttachResponse.Close();
}
PROPPATCHResponse.Close();
}
//清理一下。
PUTResponse.Close();
我在msdn上找到了答案。人们必须仔细阅读这篇文章才能得到真正的答案,但解决方案奏效了

 strBody = "To: " + strTo + "\n" +
                "Subject: " + (string.IsNullOrEmpty(message.Subject) ? "" : message.Subject) + "\n" +
            "Date: " + System.DateTime.Now + "\n" +
            "X-Mailer: test mailer" + "\n" +
            "MIME-Version: 1.0" + "\n" +
            "Content-Type: text/html;" + "\n" +
            "Charset = \"iso-8859-1\"" + "\n" +
            "Content-Transfer-Encoding: 8bit" + "\n" +
            "\n" + (string.IsNullOrEmpty(message.HtmlBody) ? "" : message.HtmlBody.Replace("<head />","").Replace("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">",""));

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

            // Add the network credentials to the request.
            // Use default credentials of the service to access the server.
            PUTRequest.Credentials = cred;


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

            // Encode the body using UTF-8.
            byte[] 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();

            if (message.Attachments != null)
            {
                //Do the PROPPATCH
                System.Net.HttpWebRequest PROPPATCHRequest;
                System.Net.WebResponse PROPPATCHResponse;
                System.IO.Stream PROPPATCHRequestStream = null;

                string strxml = "<?xml version='1.0'?>" +
                "<d:propertyupdate xmlns:d='DAV:'>" +
                "<d:set>" +
                "<d:prop>" +
                "<isCollection xmlns='DAV:'>False</isCollection>" +
                "</d:prop>" +
                "</d:set>"
                + "<g:remove>"
                + "<g:prop><m:date/></g:prop>"
                + "</g:remove>" 
                + "</d:propertyupdate>";

                PROPPATCHRequest = (System.Net.HttpWebRequest)HttpWebRequest.Create(tgtUri);
                PROPPATCHRequest.Credentials = cred;
                PROPPATCHRequest.Headers.Set("Translate", "f");
                PROPPATCHRequest.ContentType = "text/xml";
                PROPPATCHRequest.ContentLength = strxml.Length;
                PROPPATCHRequest.Method = "PROPPATCH";
                byte[] PROPPATCHbytes = Encoding.UTF8.GetBytes(strxml);
                PROPPATCHRequest.ContentLength = PROPPATCHbytes.Length;
                PROPPATCHRequestStream = PROPPATCHRequest.GetRequestStream();
                PROPPATCHRequestStream.Write(PROPPATCHbytes, 0, PROPPATCHbytes.Length);
                PROPPATCHRequestStream.Close();
                PROPPATCHResponse = (System.Net.HttpWebResponse)PROPPATCHRequest.GetResponse();


                foreach (KeyValuePair<string, byte[]> attachment in message.Attachments)
                {
                    System.IO.Stream PUTAttachRequestStream = null;
                    System.Net.HttpWebRequest PUTAttachRequest;
                    System.Net.WebResponse PUTAttachResponse;
                    //Attach File: This could be put in a loop to attach more than one file.
                    string FileName = attachment.Key; //@"2842498_794802035296_Label1.pdf";
                    string attachURI = tgtUri + "/" + FileName;
                    PUTAttachRequest = (System.Net.HttpWebRequest)HttpWebRequest.Create(attachURI);
                    PUTAttachRequest.Credentials = cred;
                    PUTAttachRequest.Method = "PUT";

                    PUTAttachRequest.ContentLength = attachment.Value.Length; //binaryData.Length;
                    PUTAttachRequestStream = PUTAttachRequest.GetRequestStream();
                    PUTAttachRequestStream.Write(attachment.Value, 0, attachment.Value.Length); //(binaryData, 0, binaryData.Length);
                    PUTAttachRequestStream.Close();

                    PUTAttachResponse = (System.Net.HttpWebResponse)PUTAttachRequest.GetResponse();
                    PUTAttachResponse.Close();
                }

                PROPPATCHResponse.Close();
            }

            // Clean up.
            PUTResponse.Close();