C# Language
Microsoft.Exchange.WebServices
Ricerca…
Recupera le impostazioni Fuori sede specificate dall'utente
Per prima cosa creiamo un oggetto ExchangeManager
, dove il costruttore si connetterà ai servizi per noi. Ha anche un metodo GetOofSettings
, che restituirà l'oggetto OofSettings
per l'indirizzo email specificato:
using System;
using System.Web.Configuration;
using Microsoft.Exchange.WebServices.Data;
namespace SetOutOfOffice
{
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("[email protected]" , RedirectionUrlValidationCallback);
Service = service;
}
private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
return redirectionUrl.Equals("https://mail.domain.com/autodiscover/autodiscover.xml");
}
public OofSettings GetOofSettings(string email)
{
return Service.GetUserOofSettings(email);
}
}
}
Possiamo ora chiamarlo altrove in questo modo:
var em = new ExchangeManager();
var oofSettings = em.GetOofSettings("[email protected]");
Aggiorna impostazioni utente specifiche fuori sede
Utilizzando la classe di seguito, possiamo connetterci a Exchange e quindi impostare le impostazioni fuori sede di un utente specifico con 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("[email protected]" , 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);
}
}
Aggiorna le impostazioni utente con quanto segue:
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 = "[email protected]";
var em = new ExchangeManager();
em.UpdateUserOof(oofstate, startDate, endDate, externalAudience, internalMessage, externalMessage, theUser);
Nota che puoi formattare i messaggi usando i tag html
standard.
Modified text is an extract of the original Stack Overflow Documentation
Autorizzato sotto CC BY-SA 3.0
Non affiliato con Stack Overflow