会议系统同步OUTLOOK

会议系统同步OUTLOOK

我们公司有一个强大的会议系统,产品小姐姐提了个需求,想要我们对全公司outlook进行改造,要求会议系统里的会议自动同步到outlook,接到需求的时候我深思熟虑了0.1秒,满口答应下来:对不起,实现不了!

产品小姐姐也挺温柔的:我不管,明天上线!


  • 实现思路:
  • 新建一个会议账号,使用ews链接exchange邮箱服务器。
  • 会议系统调用我的接口,告诉我会议时间,主题,内容,地点,哪些参会人等信息
  • 我使用会议账号发送会议邀请,并且记录会议唯一ID,通过此ID后期进行会议更改,取消等操作

今天通个宵,应该能赶上明天固传

  • 环境:
  • .NET Framework 4.5.2 框架
  • Web API 程序
  • 引用
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Web.Http;
using System.Web.Script.Serialization;
using System.Text;
using Microsoft.Exchange.WebServices.Data;
using MySql.Data.MySqlClient;
using System.Data;
using Threading_Tasks = System.Threading.Tasks;
  • 创建service服务器连接串
public ExchangeService servicevalue()
{
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2, TimeZoneInfo.Local);
                service.Credentials = new WebCredentials("mettingaccount", "mettingaccount_password", "contoso.com");
                service.TraceEnabled = true;
                service.TraceFlags = TraceFlags.All;
                service.Url = new Uri("https://mail.contoso.com/ews/exchange.asmx");
}
  • 创建会议信息参数实体
public class meetingmessagevalue
{
    /// <summary>
    /// 会议主题
    /// </summary>
    public string subject { get; set; }
    /// <summary>
    /// 会议内容
    /// </summary>
    public string body { get; set; }
    /// <summary>
    /// 会议开始时间
    /// </summary>
    public DateTime starttime { get; set; }
    /// <summary>
    /// 会议结束时间
    /// </summary>
    public DateTime endtime { get; set; }
    /// <summary>
    /// 会议地点
    /// </summary>
    public string location { get; set; }
    /// <summary>
    /// 参会人列表
    /// </summary>
    public List<string> Recipient { get; set; }
    /// <summary>
    /// 会议开始前提示时间
    /// </summary>
    public int ReminderMinutesBeforeStart { get; set; }

}
  • 发送会议接口主方法
[HttpPost]
public HttpResponseMessage Createmeeting(meetingmessagevalue mailvalue)
{
    try
    {
        string subject = mailvalue.subject;
        string body = mailvalue.body;
        string location = mailvalue.location;
        int ReminderMinutesBeforeStart = mailvalue.ReminderMinutesBeforeStart;
        List<string> Recipient = mailvalue.Recipient;
        DateTime starttime = mailvalue.starttime;
        DateTime endtime = mailvalue.endtime;
        ExchangeService service = servicevalue()
        Appointment meeting = new Appointment(service);
        meeting.Subject = subject;
        meeting.Body = body;
        meeting.EndTimeZone = TimeZoneInfo.Local;
        meeting.StartTimeZone = TimeZoneInfo.Local;
        meeting.Start = starttime;
        meeting.End = endtime;
        meeting.Location = location;
        meeting.IsResponseRequested = false;
        meeting.AllowNewTimeProposal = false;
        foreach (string text in Recipient)
        {
            meeting.RequiredAttendees.Add(text);
        }
        meeting.ReminderMinutesBeforeStart = ReminderMinutesBeforeStart;
        meeting.Save(SendInvitationsMode.SendToAllAndSaveCopy);
        Item item = Item.Bind(service, meeting.Id, new PropertySet(ItemSchema.Subject));
        bool isSuccess = true;
        var result = new { isSuccess = isSuccess, message = item.Id.UniqueId };
        HttpResponseMessage resultjson = toJson(result);
        return resultjson;
    }
    catch (Exception ex)
    {
        var message = new { message = ex.Message };
        var result = new { isSuccess = false, message = message };
        HttpResponseMessage resultjson = toJson(result);
        return resultjson;
    }
}
  • 使用postman测试,返回message为会议ID

 

  • Outlook收到会议邀请

发表评论

电子邮件地址不会被公开。 必填项已用*标注