简体   繁体   English

通过移动设备将Outlook设置为不在办公室

[英]Setting Outlook out of office from a mobile

I've been tasked with writing a mobile app (using xamarin) that will allow you to set your Outlook out-of-office. 我的任务是编写一个移动应用程序(使用xamarin),该应用程序允许您将Outlook设置为不在办公室。 Many of the examples I've found are using interop, which won't build within a mobile application. 我发现的许多示例都在使用互操作性,而互操作性不会在移动应用程序中构建。 Can anyone recommend an alternative method? 谁能推荐一种替代方法?

You can use Exchange Web Services to do that. 您可以使用Exchange Web服务执行此操作。

from http://msdn.microsoft.com/en-us/library/office/aa563356(v=exchg.140).aspx : : 来自http://msdn.microsoft.com/zh-cn/library/office/aa563356(v=exchg.140).aspx ::

static void SetOOF(ExchangeServiceBinding service)
{
    // Identify the user mailbox for which to set OOF information.
    EmailAddress emailAddress = new EmailAddress();

    emailAddress.Address = "donhall@example.com";
    emailAddress.Name = String.Empty;

    UserOofSettings OOFSettings = new UserOofSettings();

    // Identify the time that a user is OOF 
    Duration duration = new Duration();
    duration.StartTime = DateTime.Now;
    duration.EndTime = DateTime.Now.AddHours(4);
    OOFSettings.Duration = duration;

    // Identify the external audience.
    OOFSettings.ExternalAudience = ExternalAudience.Known;

    // Create the reply messages.
    ReplyBody internalReply = new ReplyBody();
    ReplyBody externalReply = new ReplyBody();
    externalReply.Message = "This is my external OOF reply";
    internalReply.Message = "This is my internal OOF reply";

    OOFSettings.ExternalReply = externalReply;
    OOFSettings.InternalReply = internalReply;

    // Set OOF state.
    OOFSettings.OofState = OofState.Enabled;

    // Create the request.
    SetUserOofSettingsRequest request = new SetUserOofSettingsRequest();
    request.Mailbox = emailAddress;
    request.UserOofSettings = OOFSettings;

    try
    {
        // Send the request and return the response.
        SetUserOofSettingsResponse response = service.SetUserOofSettings(request);
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
    }
}

Allan - thanks for your response. 艾伦-感谢您的回复。 I finally got it working but the library seems to have been modified, so in case anyone else needs it, here's my code: 我终于让它工作了,但是该库似乎已被修改,因此如果其他人需要它,这是我的代码:

  ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);

        service.Url = new Uri("https://<server>/EWS/Exchange.asmx");

        EmailAddress emailAddress = new EmailAddress();

        emailAddress.Address = "nick.wright@<domain>";
        emailAddress.Name = String.Empty;

        OofSettings OOFSettings = new OofSettings();

        OOFSettings.Duration = new TimeWindow(DateTime.Now, DateTime.Now.AddDays(1));

        OOFSettings.ExternalAudience = OofExternalAudience.All;

        OofReply internalReply = new OofReply();
        OofReply externalReply = new OofReply();

        externalReply.Message = "This is my external OOF reply";
        internalReply.Message = "This is my internal OOF reply";

        OOFSettings.ExternalReply = externalReply;
        OOFSettings.InternalReply = internalReply;

        OOFSettings.State = OofState.Disabled;

        try
        {
            service.SetUserOofSettings("nick.wright@<domain>", OOFSettings);
        }
        catch (Exception ex)
        {
        }

I came across a couple of errors. 我遇到了两个错误。 Firstly, the documented URL is incorrect, so this fixed it: 首先,记录的URL不正确,因此可以解决此问题:

exchange web service error - the remote server returned an error 405 method not allowed 交换Web服务错误-远程服务器返回不允许的错误405方法

Secondly, the Exchange version needed explicitly setting (although once set, I could set it to any version and it worked!?!) 其次,Exchange版本需要显式设置(尽管设置了一次,但我可以将其设置为任何版本并且可以使用!!!)

http://social.technet.microsoft.com/Forums/exchange/en-US/df5c0c5e-1ea6-4ee9-824c-e8cb4930e291/ews-managed-api-error-exchange-server-doesnt-support-requested-version?forum=exchangesvrdevelopment http://social.technet.microsoft.com/Forums/exchange/zh-CN/df5c0c5e-1ea6-4ee9-824c-e8cb4930e291/ews-managed-api-error-exchange-server-doesnt-support-requested-version?论坛= exchangesvr发展

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM