本文整理汇总了C#中ExchangeService.AutodiscoverUrl方法的典型用法代码示例。如果您正苦于以下问题:C# ExchangeService.AutodiscoverUrl方法的具体用法?C# ExchangeService.AutodiscoverUrl怎么用?C# ExchangeService.AutodiscoverUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExchangeService
的用法示例。
在下文中一共展示了ExchangeService.AutodiscoverUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
private static void Main(string[] args)
{
//ExchangeService service = new ExchangeService();
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1, TimeZoneInfo.Local) { UseDefaultCredentials = true };
service.AutodiscoverUrl(@"[email protected]");
Task newTask = new Task(service);
newTask.Contacts.Add("[email protected]");
newTask.DueDate = DateTime.Now.AddDays(1);
newTask.PercentComplete = 48;
newTask.StartDate = DateTime.Now;
newTask.Status = TaskStatus.InProgress;
//newTask.TotalWork = 50;
newTask.Body = "Hello";
newTask.Subject = "Test Issue Task";
newTask.ReminderDueBy = newTask.DueDate.Value;
IList<Task> items = new List<Task>();
items.Add(newTask);
FolderId id = new FolderId(WellKnownFolderName.Tasks);
//service.CreateItems(items, id, null, null);
}
示例2: GetExchangeServiceBuilder
public static Func<ExchangeService> GetExchangeServiceBuilder(string username, string password, string serviceUrl)
{
// if we don't get a service URL in our configuration, run auto-discovery the first time we need it
var svcUrl = new Lazy<string>(() =>
{
if (!string.IsNullOrEmpty(serviceUrl))
{
return serviceUrl;
}
var log = log4net.LogManager.GetLogger(MethodInfo.GetCurrentMethod().DeclaringType);
log.DebugFormat("serviceUrl wasn't configured in appSettings, running auto-discovery");
var svc = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
svc.Credentials = new WebCredentials(username, password);
svc.AutodiscoverUrl(username, url => new Uri(url).Scheme == "https");
log.DebugFormat("Auto-discovery complete - found URL: {0}", svc.Url);
return svc.Url.ToString();
});
return () =>
new ExchangeService(ExchangeVersion.Exchange2010_SP1)
{
Credentials = new WebCredentials(username, password),
Url = new Uri(svcUrl.Value),
};
}
示例3: CreateConnection
public static ExchangeService CreateConnection(string emailAddress)
{
// Hook up the cert callback to prevent error if Microsoft.NET doesn't trust the server
ServicePointManager.ServerCertificateValidationCallback =
delegate(Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
};
ExchangeService service = null;
if (!string.IsNullOrEmpty(Configuration.ExchangeAddress))
{
service = new ExchangeService();
service.Url = new Uri(Configuration.ExchangeAddress);
}
else
{
if (!string.IsNullOrEmpty(emailAddress))
{
service = new ExchangeService();
service.AutodiscoverUrl(emailAddress);
}
}
return service;
}
示例4: ConnectToServiceWithImpersonation
public static ExchangeService ConnectToServiceWithImpersonation(
IUserData userData,
string impersonatedUserSMTPAddress,
ITraceListener listener)
{
ExchangeService service = new ExchangeService(userData.Version);
if (listener != null)
{
service.TraceListener = listener;
service.TraceFlags = TraceFlags.All;
service.TraceEnabled = true;
}
service.Credentials = new NetworkCredential(userData.EmailAddress, userData.Password);
ImpersonatedUserId impersonatedUserId =
new ImpersonatedUserId(ConnectingIdType.SmtpAddress, impersonatedUserSMTPAddress);
service.ImpersonatedUserId = impersonatedUserId;
if (userData.AutodiscoverUrl == null)
{
service.AutodiscoverUrl(userData.EmailAddress, RedirectionUrlValidationCallback);
userData.AutodiscoverUrl = service.Url;
}
else
{
service.Url = userData.AutodiscoverUrl;
}
return service;
}
示例5: GetExchangeService
public static ExchangeService GetExchangeService(string emailAddress, string username, string password, ExchangeVersion exchangeVersion, Uri serviceUri)
{
var service = new ExchangeService(exchangeVersion);
service.Credentials = new WebCredentials(username, password);
service.EnableScpLookup = false;
if (serviceUri == null)
{
service.AutodiscoverUrl(emailAddress, (url) =>
{
bool result = false;
var redirectionUri = new Uri(url);
if (redirectionUri.Scheme == "https")
{
result = true;
}
return result;
});
}
else
{
service.Url = serviceUri;
}
return service;
}
示例6: GetNextAppointments
public AppointmentGroup GetNextAppointments()
{
try
{
var newAppointments = new AppointmentGroup();
var service = new ExchangeService();
service.UseDefaultCredentials = true;
service.AutodiscoverUrl(UserPrincipal.Current.EmailAddress);
DateTime from = DateTime.Now.AddMinutes(-5);
DateTime to = DateTime.Today.AddDays(1);
IEnumerable<Appointment> appointments =
service.FindAppointments(WellKnownFolderName.Calendar, new CalendarView(from, to))
.Select(MakeAppointment);
newAppointments.Next =
appointments.Where(o => o != null && o.Start >= DateTime.Now)
.OrderBy(o => o.Start).ToList();
nextAppointments = newAppointments;
return newAppointments;
}
catch (Exception e)
{
Trace.WriteLine(e.ToString());
return nextAppointments;
}
}
示例7: SignUp
public ActionResult SignUp(SignUpView view)
{
String smtpAddess = "[email protected]";
String password = "(t35t1ng)";
var exchangeService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
exchangeService.Credentials = new WebCredentials(smtpAddess, password);
exchangeService.AutodiscoverUrl(smtpAddess, RedirectionUrlValidationCallback);
Contact contact = new Contact(exchangeService);
contact.GivenName = view.GivenName;
contact.Surname = view.Surname;
contact.FileAsMapping = FileAsMapping.SurnameCommaGivenName;
contact.EmailAddresses[EmailAddressKey.EmailAddress1] = new EmailAddress(view.Email);
try
{
contact.Save();
}
catch(Exception e)
{
ViewBag.Message = e.Message;
return View(view);
}
return View("Thanks");
}
示例8: ConnectToService
public static ExchangeService ConnectToService(
IUserData userData,
ITraceListener listener)
{
ExchangeService service = new ExchangeService(userData.Version);
if (listener != null)
{
service.TraceListener = listener;
service.TraceFlags = TraceFlags.All;
service.TraceEnabled = true;
}
service.Credentials = new NetworkCredential(userData.EmailAddress, userData.Password);
if (userData.AutodiscoverUrl == null)
{
service.AutodiscoverUrl(userData.EmailAddress, RedirectionUrlValidationCallback);
userData.AutodiscoverUrl = service.Url;
}
else
{
service.Url = userData.AutodiscoverUrl;
}
return service;
}
示例9: ConnectToService
public static ExchangeService ConnectToService(IUserData userData, ITraceListener listener)
{
ExchangeService service = new ExchangeService(userData.Version);
if (listener != null)
{
service.TraceListener = listener;
service.TraceFlags = TraceFlags.All;
service.TraceEnabled = true;
}
service.Credentials = new NetworkCredential(userData.EmailAddress, userData.Password);
if (userData.AutodiscoverUrl == null)
{
Console.Write(string.Format("Using Autodiscover to find EWS URL for {0}. Please wait... ", userData.EmailAddress));
service.AutodiscoverUrl(userData.EmailAddress, RedirectionUrlValidationCallback);
userData.AutodiscoverUrl = service.Url;
Console.WriteLine("Autodiscover Complete");
}
else
{
service.Url = userData.AutodiscoverUrl;
}
return service;
}
示例10: CreateService
public ExchangeService CreateService(string UserID, string UserPassword, string workinghours)
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
try
{
service.UseDefaultCredentials = false;
string workingHrs =workinghours;///default from web.config
string sendUserMailAddress = UserID;// ConfigSettings.settings["SenderEmail"];// Config.SenderEmail;
string sendUserMailPwd = UserPassword;// ConfigSettings.settings["SenderPassword"]; //Config.SenderPassword;
if (sendUserMailAddress != null && sendUserMailPwd != null)
{
service.Credentials = new WebCredentials(sendUserMailAddress, sendUserMailPwd);
service.AutodiscoverUrl(sendUserMailAddress, RedirectionUrlValidationCallback);
}
}
catch
{
}
return service;
}
示例11: GetExchangeService
public ExchangeService GetExchangeService(ExchangeServerSettings exchangeServerSettings)
{
ExchangeVersion exchangeVersion;
var isValidVersion = Enum.TryParse(exchangeServerSettings.ExchangeVersion, true, out exchangeVersion);
if (isValidVersion)
{
var service = new ExchangeService(exchangeVersion)
{
UseDefaultCredentials = exchangeServerSettings.UsingCorporateNetwork,
EnableScpLookup = false,
Url = new Uri(exchangeServerSettings.ExchangeServerUrl)
};
if (string.IsNullOrEmpty(exchangeServerSettings.ExchangeServerUrl))
{
service.AutodiscoverUrl(exchangeServerSettings.EmailId);
}
if (!exchangeServerSettings.UsingCorporateNetwork)
{
service.Credentials = new WebCredentials(exchangeServerSettings.EmailId,
exchangeServerSettings.Password,
exchangeServerSettings.Domain);
}
//service.Credentials = new WebCredentials("[email protected]", "password");
return service;
}
return null;
}
示例12: EwsClient
/// <summary>
/// Initialize a new EwsClient using the specified username and password to connect to the specified version of EWS. An attempt is made to autodiscovered the EWS endpoint.
/// </summary>
/// <param name="username">A user with login rights on the specified <paramref name="domain"/>.</param>
/// <param name="password">The password for the specified <paramref name="username"/>.</param>
/// <param name="domain">The Exchange domain.</param>
/// <param name="exchangeVersion">The version of Exchange.</param>
/// <remarks>
/// In order for autodiscovery of an EWS endpoint to work, there may be additional Exchange configuration required.
/// See http://msdn.microsoft.com/en-us/library/office/jj900169(v=exchg.150).aspx.
/// </remarks>
public EwsClient(string username, string password, string domain, ExchangeVersion exchangeVersion)
{
exchangeService = new ExchangeService(exchangeVersion)
{
Credentials = new WebCredentials(username, password, domain),
};
exchangeService.AutodiscoverUrl(String.Format("{0}@{1}", username, domain));
}
示例13: Login
public ActionResult Login(ExLogOnViewModel model, bool hosted = false)
{
User userObj = (User)Session["user"];
var acc = accRepository.Accounts.FirstOrDefault(x => x.ID == userObj.AccountID);
//credRepository.SetConnectionString(acc.ConnectionString);
ExchangeService srv = null;
if (model.SelectedCredentialID != 0)
{
var creds = credRepository.Credentials.FirstOrDefault(x => x.ID == model.SelectedCredentialID);
if (creds.IsHostedExchange)
{
srv = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
srv.Credentials = new WebCredentials(creds.EmailAddress, creds.Password);
srv.AutodiscoverUrl(creds.EmailAddress, RedirectionUrlValidationCallback);
}
else
{
if (creds.ServerVersion == "2007SP1") srv = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
else if (creds.ServerVersion == "2010") srv = new ExchangeService(ExchangeVersion.Exchange2010);
else if (creds.ServerVersion == "2010SP1") srv = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
else srv = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
srv.Credentials = new WebCredentials(creds.UserName, creds.Password);
srv.AutodiscoverUrl(creds.EmailAddress, RedirectionUrlValidationCallback);
}
Session["srv"] = srv;
Session["srvEmail"] = creds.EmailAddress;
}
else
{
if (hosted)
{
srv = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
srv.Credentials = new WebCredentials(model.Credentials.EmailAddress, model.Credentials.Password);
srv.AutodiscoverUrl(model.Credentials.EmailAddress, RedirectionUrlValidationCallback);
model.Credentials.URL = srv.Url.AbsoluteUri;
}
else
{
if (model.Credentials.ServerVersion == "2007SP1") srv = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
else if (model.Credentials.ServerVersion == "2010") srv = new ExchangeService(ExchangeVersion.Exchange2010);
else if (model.Credentials.ServerVersion == "2010SP1") srv = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
else srv = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
srv.Credentials = new WebCredentials(model.Credentials.UserName, model.Credentials.Password);
srv.AutodiscoverUrl(model.Credentials.EmailAddress, RedirectionUrlValidationCallback);
model.Credentials.URL = srv.Url.AbsoluteUri;
}
Session["srv"] = srv;
Session["srvEmail"] = model.Credentials.EmailAddress;
model.Credentials.IsHostedExchange = hosted;
credRepository.SaveCredential(model.Credentials);
}
return Redirect(model.ReturnUrl);
}
示例14: Main
public static void Main(string[] args)
{
ServicePointManager.ServerCertificateValidationCallback = EwsAuthentication.CertificateValidationCallBack;
System.Console.WriteLine("Enter your email address");
// ReSharper disable once PossibleNullReferenceException
var userName = System.Console.ReadLine().Trim();
var startDate = DateTime.Now - TimeSpan.FromDays(365*6);
while (startDate.DayOfWeek != DayOfWeek.Monday)
{
startDate -= TimeSpan.FromDays(1);
}
List<Meeting> meetings = null;
if (File.Exists(userName))
{
meetings = JsonConvert.DeserializeObject<List<Meeting>>(File.ReadAllText(userName));
}
else
{
System.Console.WriteLine("Looks like I need to connect to Exchange. Enter your password. I won't steal it. Honest");
var password = Console.ReadPassword();
var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1)
{
Credentials = new WebCredentials(userName, password),
TraceEnabled = false,
TraceFlags = TraceFlags.None
};
service.AutodiscoverUrl(userName, EwsAuthentication.RedirectionUrlValidationCallback);
meetings = new ExchangeRetriever(service).MeetingStatistics(startDate, DateTime.Now);
File.WriteAllText(userName, JsonConvert.SerializeObject(meetings));
}
using (var streamWriter = File.CreateText("accepted_meetings.csv"))
{
Reports.AcceptedMeetings(meetings, streamWriter);
}
using (var output = File.CreateText("accepted_meetings_per_week.csv"))
{
Reports.TotalMeetingDuration(meetings, startDate, output);
}
using (var output = File.CreateText("contiguous_time_per_day.csv"))
{
Reports.ContiguousTimePerDay(output, meetings);
}
}
示例15: actualizarRevisionDirectivaE
public string actualizarRevisionDirectivaE(string asunto, string fechaInicio, string fechaLimite, string cuerpoTarea, string ubicacion)
{
string error = "";
try
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.UseDefaultCredentials = true;
service.Credentials = new WebCredentials("xxxxxxxxxxxx", "xxxxx", "xxxx");//@uanl.mx
service.AutodiscoverUrl("xxxxxxxxxxxxxxxxx");
string querystring = "Subject:'"+asunto +"'";
ItemView view = new ItemView(1);
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Calendar, querystring, view);// <<--- Esta parte no la se pasar a VB
if (results.TotalCount > 0)
{
if (results.Items[0] is Appointment) //if is an appointment, could be other different than appointment
{
Appointment appointment = results.Items[0] as Appointment; //<<--- Esta parte no la se pasar a VB
if (appointment.MeetingRequestWasSent)//if was send I will update the meeting
{
appointment.Start = Convert.ToDateTime(fechaInicio);
appointment.End = Convert.ToDateTime(fechaLimite);
appointment.Body = cuerpoTarea;
appointment.Location = ubicacion;
appointment.Update(ConflictResolutionMode.AutoResolve);
}
else//if not, i will modify and sent it
{
appointment.Start = Convert.ToDateTime(fechaInicio);
appointment.End = Convert.ToDateTime(fechaLimite);
appointment.Body = cuerpoTarea;
appointment.Location = ubicacion;
appointment.Save(SendInvitationsMode.SendOnlyToAll);
}
}
}
else
{
error = "Wasn't found it's appointment";
return error;
}
return error;
}
catch
{
return error = "an error happend";
}
}