更新特定使用者的外出設定
使用下面的類,我們可以連線到 Exchange,然後使用 UpdateUserOof
設定特定使用者的不在辦公室設定:
using System;
using System.Web.Configuration;
using Microsoft.Exchange.WebServices.Data;
class ExchangeManager
{
private ExchangeService Service;
public ExchangeManager()
{
var password = WebConfigurationManager.ConnectionStrings["Password"].ConnectionString;
Connect("exchangeadmin", password);
}
private void Connect(string username, string password)
{
var service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.Credentials = new WebCredentials(username, password);
service.AutodiscoverUrl("autodiscoveremail@domain.com" , RedirectionUrlValidationCallback);
Service = service;
}
private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
return redirectionUrl.Equals("https://mail.domain.com/autodiscover/autodiscover.xml");
}
/// <summary>
/// Updates the given user's Oof settings with the given details
/// </summary>
public void UpdateUserOof(int oofstate, DateTime starttime, DateTime endtime, int externalaudience, string internalmsg, string externalmsg, string emailaddress)
{
var newSettings = new OofSettings
{
State = (OofState)oofstate,
Duration = new TimeWindow(starttime, endtime),
ExternalAudience = (OofExternalAudience)externalaudience,
InternalReply = internalmsg,
ExternalReply = externalmsg
};
Service.SetUserOofSettings(emailaddress, newSettings);
}
}
使用以下內容更新使用者設定:
var oofState = 1;
var startDate = new DateTime(01,08,2016);
var endDate = new DateTime(15,08,2016);
var externalAudience = 1;
var internalMessage = "I am not in the office!";
var externalMessage = "I am not in the office <strong>and neither are you!</strong>"
var theUser = "theuser@domain.com";
var em = new ExchangeManager();
em.UpdateUserOof(oofstate, startDate, endDate, externalAudience, internalMessage, externalMessage, theUser);
請注意,你可以使用標準 html
標記格式化訊息。