远程服务器返回错误405方法不允许

时间:2014-12-16 07:15:02

标签: c# aspose

我正在尝试将邮箱从收件箱移至已删除的文件夹。但是,当我运行该程序时,我收到上述错误消息。请帮忙解决这个问题。 这是我的代码

 string mailboxURI = "URL//"; 

        string username = "username";
        string password = "Password";
        string domain = "domain name";

        Console.WriteLine("Connecting to Exchange Server....");
        try
        {
            NetworkCredential credential = new NetworkCredential(username, password, domain);
            ExchangeClient client = new ExchangeClient(mailboxURI, credential);

            ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo();

            // List all messages from Inbox folder
            Console.WriteLine("Listing all messages from Inbox....");
            ExchangeMessageInfoCollection msgInfoColl = client.ListMessages(mailboxInfo.InboxUri);
            foreach (ExchangeMessageInfo msgInfo in msgInfoColl)
            {
                // Move message to "Deleted" folder, after processing certain messages
                // based on some criteria
                if (msgInfo.Date != DateTime.Today)
                {
                    // Move it
                    client.MoveItems(msgInfo.UniqueUri, client.MailboxInfo.RootUri + "/Deleted/" + msgInfo.Subject);
                    Console.WriteLine("Message moved...." + msgInfo.Subject);
                }
                else
                {
                    Console.WriteLine("Not moved:" + msgInfo.Subject);
                }
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error:"+ex.Message);
            Console.Read();
        }
    }

1 个答案:

答案 0 :(得分:3)

当服务器超出服务器上的方法与您的http请求类型不匹配时,会出现此错误。

例如。服务器期待http GET方法但是你的代码使用POST方法与服务器通信或反之。

您可能希望更改代码中的方法类型。

干杯 了Anant