c#使用Microsoft.Office.Interop.Outlook发送会议请求。如何正确切换发件人帐户

时间:2019-01-30 10:16:29

标签: c# email outlook meeting-request

我正在使用Microsoft.Office.Interop.Outlook在地址之间发送自动会议请求。

让我们说我有2个人person1@mail.comperson2@mail.com。按照我的逻辑,我只需要在这两个人之间建立会议。

由于Microsoft.Office.Interop.Outlook需要添加组织者帐户才能请求,因此我创建了一个名为organizer@mail.com的特殊邮件帐户,并将此帐户添加到了Outlook中,因此目前我的Outlook中有2个帐户。第一个是我的主要main@mail.com,第二个是organizer@mail.com

现在按照我的逻辑,我将当前用户切换为organizer@mail.com并发送请求。结果,person1person2organizer获得正确的会议请求。如果不是小问题,一切都应该很好。此请求还将会议添加到我的main@mail.com日历中。

您能看看我的代码是否有问题吗?

Application outlook = new Application();
AppointmentItem appointment =
    outlook.CreateItem(OlItemType.olAppointmentItem) as AppointmentItem;

Accounts accounts = outlook.Session.Accounts;

var account = accounts["organizer@mail.com"];

appointment.SendUsingAccount = account;

appointment.Start = DateTime.Now.AddHours(8);
appointment.End = DateTime.Now.AddHours(9);
appointment.Body =
  "Test Message";
appointment.AllDayEvent = false;
appointment.Subject = "Test ";
appointment.Recipients.Add("person1@mail.com");
appointment.Recipients.Add("person2@mail.com");
Recipients sentTo = appointment.Recipients;
Recipient sentInvite = null;
sentTo.Add("person2@mail.com");
sentInvite = sentTo.Add("person1@mail.com");

sentInvite.Type = (int) OlMeetingRecipientType
   .olRequired;

appointment.IsOnlineMeeting = true;
        appointment.MeetingStatus = Microsoft.Office.Interop.Outlook.OlMeetingStatus.olMeeting;


appointment.Save();
appointment.Send();

我可以不将会议保存到我的main帐户中吗?

我将不胜感激。

0 个答案:

没有答案