Microsoft.Exchange.WebServices 15.0.0.0
2、配置文件描述
<add key="BindIP" value="ocs-dev-ax.ocs.com" />
<add key="BindPassword" value="123456!" />
<add key="BindUserName" value="administrator" />
<add key="BindDomain" value="OCS" />
3、获取exchange service代码(初始化)
/// <summary>
/// 获取ExchangeService
/// </summary>
/// <returns></returns>
public ExchangeService getservice()
string Host = System.Configuration.ConfigurationManager.AppSettings["BindIP"];
string BindPassword = System.Configuration.ConfigurationManager.AppSettings["BindPassword"];
string BindUserName = System.Configuration.ConfigurationManager.AppSettings["BindUserName"];
string BindDomain = System.Configuration.ConfigurationManager.AppSettings["BindDomain"];
ExchangeService service = new ExchangeService();
service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new NetworkCredential(BindUserName, BindPassword, BindDomain);
Uri uri = new Uri("https://" + Host + "/ews/exchange.asmx");
service.Url = uri;
service.TraceEnabled = true;
service.UseDefaultCredentials = false;
service.PreAuthenticate = false;
catch (Exception ex)
return service;
4、操作exchange用户日历数据(获取、新增、修改、删除用户日历会议数据)
重点:如果在获取时候报错误信息:The specified folder could not be found in the store需要调用方法runPowerShell ,请参考【.Net】在.net项目中执行power shell命令
string runPSResult = runPowerShell(userName + "@" + BindDomain + ".com");
public List<AppointmentModel> SearchCalendar(string userName, DateTime StartDate, DateTime EndDate)
string BindDomain = System.Configuration.ConfigurationManager.AppSettings["BindDomain"];
ExchangeService service = getservice();
List<AppointmentModel> appList = new List<AppointmentModel>();
//如果在获取时候报错误信息:The specified folder could not be found in the store需要调用方法runPowerShell
string runPSResult = runPowerShell(userName + "@" + BindDomain + ".com");
if (runPSResult == "")
//验证服务器证书回调自动验证
service.TraceEnabled = true;
ServicePointManager.ServerCertificateValidationCallback += CheckValidationResult;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
const int NUM_APPTS = 5;
// Initialize the calendar folder object with only the folder ID.
Mailbox mb = new Mailbox(userName + "@OCS.com");
FolderId folderIdFromCalendar = new FolderId(WellKnownFolderName.Calendar, mb);
CalendarFolder calendar = CalendarFolder.Bind(service, folderIdFromCalendar);
// Set the start and end time and number of appointments to retrieve.
CalendarView cView = new CalendarView(StartDate, EndDate, NUM_APPTS);
// Limit the properties returned to the appointment's subject, start time, and end time.
cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);
// Retrieve a collection of appointments by using the calendar view.
FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
foreach (Appointment app in appointments)
AppointmentModel appointmentModel = new AppointmentModel();
Appointment a = Appointment.Bind(service, new ItemId(app.Id.UniqueId));
appointmentModel.Id = a.Id.UniqueId;
appointmentModel.Body = a.Body;
appointmentModel.Subject = a.Subject;
appointmentModel.StartDate = a.Start;
appointmentModel.EndDate = a.End;
appointmentModel.IsAllDayEvent = a.IsAllDayEvent;
appointmentModel.IsPrivate = (((Item)a).Sensitivity == Sensitivity.Private) ? true : false;
appointmentModel.RequiredAttendees = new List<string>();
foreach (Attendee required in a.RequiredAttendees)
appointmentModel.RequiredAttendees.Add(required.Address);
appointmentModel.OptionalAttendees = new List<string>();
foreach (Attendee optional in a.OptionalAttendees)
appointmentModel.OptionalAttendees.Add(optional.Address);
appointmentModel.IsMeeting = a.IsMeeting;
appointmentModel.Id = app.Id.UniqueId;
appointmentModel.Subject = app.Subject;
appointmentModel.StartDate = app.Start;
appointmentModel.EndDate = app.End;
appList.Add(appointmentModel);
return appList;
private bool AddNewInviteCalendar(string userName, AppointmentModel appointmentModel, ref string id)
ExchangeService service = getservice();
//如果在获取时候报错误信息:The specified folder could not be found in the store需要调用方法runPowerShell
string runPSResult = runPowerShell(userName + "@" + BindDomain + ".com");
//验证服务器证书回调自动验证
ServicePointManager.ServerCertificateValidationCallback += CheckValidationResult;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Appointment appointment = new Appointment(service);
appointment.Subject = appointmentModel.Subject;
appointment.Body = appointmentModel.Body;
appointment.Start = appointmentModel.StartDate;
appointment.End = appointmentModel.EndDate;
appointment.IsAllDayEvent = appointmentModel.IsAllDayEvent;//全天事件
appointment.Sensitivity = (appointmentModel.IsPrivate) ? Sensitivity.Private : Sensitivity.Normal;//是否私人,去掉是Sensitivity.Normal
appointment.Location = appointmentModel.Location; //会议地点//20201225
if (appointmentModel.RequiredAttendees != null && appointmentModel.RequiredAttendees.Count > 0)
foreach (String rAttendee in appointmentModel.RequiredAttendees)
appointment.RequiredAttendees.Add(rAttendee);
if (appointmentModel.OptionalAttendees != null && appointmentModel.OptionalAttendees.Count > 0)
foreach (String oAttendee in appointmentModel.OptionalAttendees)
appointment.OptionalAttendees.Add(oAttendee);
appointment.Save(new FolderId(WellKnownFolderName.Calendar, userName + "@OMS.com"), SendInvitationsMode.SendToAllAndSaveCopy);
appointmentModel.Id = appointment.Id.UniqueId;
id = appointmentModel.Id;
return true;
catch (Exception ex)
//WriteLog("add error,subject:[" + appointmentModel.Subject + "] body:[" + appointmentModel.Body + "]msg:" + ex.ToString(), true);
return false;
private bool ModifyInviteCalendar(AppointmentModel appointmentModel)
ExchangeService service = getservice();
ServicePointManager.ServerCertificateValidationCallback += CheckValidationResult;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Appointment appointment = Appointment.Bind(service, new ItemId(appointmentModel.Id));
if (appointment != null)
appointment.Subject = appointmentModel.Subject;
appointment.Body = appointmentModel.Body;
appointment.StartTimeZone = TimeZoneInfo.FindSystemTimeZoneById("China Standard Time");
//appointment.EndTimeZone = TimeZoneInfo.FindSystemTimeZoneById("China Standard Time");
appointment.Start = appointmentModel.StartDate;
appointment.End = appointmentModel.EndDate;
appointment.IsAllDayEvent = appointmentModel.IsAllDayEvent;
appointment.Sensitivity = (appointmentModel.IsPrivate) ? Sensitivity.Private : Sensitivity.Normal;//是否私人,去掉是Sensitivity.Normal
appointment.Location = appointmentModel.Location; //修改地点//20201225
if (appointmentModel.RequiredAttendees != null && appointmentModel.RequiredAttendees.Count > 0)
appointment.RequiredAttendees.Clear();
foreach (String rAttendee in appointmentModel.RequiredAttendees)
appointment.RequiredAttendees.Add(rAttendee);
appointment.RequiredAttendees.Clear();
if (appointmentModel.OptionalAttendees != null && appointmentModel.OptionalAttendees.Count > 0)
appointment.OptionalAttendees.Clear();
foreach (String oAttendee in appointmentModel.OptionalAttendees)
appointment.OptionalAttendees.Add(oAttendee);
appointment.OptionalAttendees.Clear();
//appointment.Sensitivity = (appointmentModel.IsPrivate) ? Sensitivity.Private : Sensitivity.Normal;//是否私人,去掉是Sensitivity.Normal
appointment.Update(ConflictResolutionMode.AlwaysOverwrite);
DateTime dt = appointment.LastModifiedTime;
return true;
//errmsgid = "not find calendar schedule";
return false;
catch (Exception ex)
// WriteLog("edit error,id:[" + appointmentModel.Id + "] msg:" + ex.ToString(), true);
//errmsgid = "edit error";
return false;
private bool DeleteCalendar(String id, ref string errmsgid)
ExchangeService service = getservice();
//验证服务器证书回调自动验证
ServicePointManager.ServerCertificateValidationCallback += CheckValidationResult;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Appointment appointment = Appointment.Bind(service, new ItemId(id));
if (appointment != null)
appointment.Subject = appointment.Subject + "(已删除)";
//appointment.Body = appointment.Body.Text.Replace(appointment.Body.Text.Substring(appointment.Body.Text.IndexOf("</body>")), "(已删除)" + appointment.Body.Text.Substring(appointment.Body.Text.IndexOf("</body>")));
if (!String.IsNullOrEmpty(appointment.Body) && !String.IsNullOrEmpty(appointment.Body.Text))
appointment.Body = appointment.Body.Text.Replace(appointment.Body.Text.Substring(appointment.Body.Text.IndexOf("</body>")), "(已删除)" + appointment.Body.Text.Substring(appointment.Body.Text.IndexOf("</body>")));
appointment.Update(ConflictResolutionMode.AlwaysOverwrite);
appointment.Delete(DeleteMode.MoveToDeletedItems);
return true;
errmsgid = "not find calendar schedule";
return false;
catch (Exception ex)
//WriteLog("delete error,id:[" + id + "] msg:" + ex.ToString(), true);
errmsgid = "del error";
return false;
<dependency>
<groupId>com.microsoft.ews-java-api</groupId>
<artifactId>ews-java-api</artifactId>
<version
EWS(Exchange Service)基本使用(获取个人会议,会议室会议内容,会议室列表,发送会议,修改会议,删除会议)
最近公司要求和exchange服务对接,所以稍微研究了一下官方文档,做出以下总结,欢迎大家补充。
先放出exchange官方开发说明文档:https://docs.microsoft.com/zh-cn/exchange/client-developer/exchange-web-services/calendars-and-ews-in-exchange
与exchange we
这个功能在2003可以通过设置邮箱策略删除,但是过渡到2010 我们通过保留策略来实现这个功能,却发现我们在新建保留标记的时候,会报如下的错误:
日历项目不受到支持,咋办呢?经过查阅一些国内外的资料,找到如下的解决办法,希望对大家能够有所帮助:
首先我们为默认的日历创建一个可管理的文件夹:
New-ManagedFolder -Name
‘DefaultCalendar’ -Defau
下面代码演示了如何获取公共日历
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Credentials = new NetworkCredential("...
代码如下: class ExchangeRate { private const string _BASEURL = “网页地址”; public const string CURRENCYCODE = “货币类型以’|’隔开”;//货币类型 public Hashtable GetValues() { Hashtable htReturn = new Hashtable(); string url = _BASEURL; //+ HttpUtility.UrlEncode(tmSet.ToString(“yyyy/MM/dd”, DateTimeFormatInfo.InvariantInf
什么是蛋液?
EggSink 是用于在 Microsoft Exchange Server 和 Google 日历之间同步数据的脚本。 写它是因为当时非 Windows 平台缺乏将日历数据从 Exchange 同步到 Google 日历的选项(通常您需要在 Microsoft Windows 上使用 Microsoft Outlook 才能使用大多数可用工具为此,其中大多数不是免费的)。
注意:EggSink 目前只对从 Exchange 日历到 Google 日历的事件进行单向同步。
EggSink 使用与 Exchange Web 服务对话,并使用与 Google 日历对话。 这两个库都包含在 hte 项目中,但将来可能会使用 Composer 进行设置。
EggSink 还需要至少 PHP 5.4。
只需下载此源代码并设置配置即可。 您需要有一个有效的 Excha
[code=html]
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
"port": 4321,
"https": true,
"initialPage": "https://enter-your-SharePoint-site/_layouts/workbench.aspx"
[/code]
将 enter-your-SharePoint-site 域更改为要用于测试 SharePoint 租户和网站的 URL。 例如:https://contoso.sharepoint.com/sites/devsite/_layouts/workbench.aspx。
启动 gulp serve
[code=javascript]
[11:17:24] Error - 'spfx-serve' sub task errored after 172 ms
No development certificate found. Generate a new certificate manually, or set the `canGenerateNewCertificate` parameter to `true` when calling `ensureCertificateAsync`.
[11:17:24] 'serve' errored after 176 ms
[/code]
我不知道咋搞 求大佬指点
【Power Apps】03 创建你的第一个Power Apps(数据源为Excel的Canvas应用)
明日天气:
【.net】通过企业微信web api给指定用户发送消息
cs2645542961:
【vs2019】vs2019(Visual Studio2019)离线安装包下载详细步骤
Tauntaun: