gpt4 book ai didi

c# - 使用 C# 在其他人的 outlook 日历中创建约会

转载 作者:太空狗 更新时间:2023-10-29 23:37:33 25 4
gpt4 key购买 nike

我想创建一个程序,可以在其他人的 Outlook 日历中创建约会。例如:如果有人向他们的老板申请五天免费,他们的老板需要能够批准并立即将其显示在该人的 outlook 日历中。我已经编写了一些代码,您可以在其中设置自己的约会。这是我的代码:

    public Form1()
{
InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)
{
AddAppointment("ConferenceRoom #2345", "We will discuss progression the group project.", "Group Project", new DateTime(2016, 02, 23, 15, 30, 52), new DateTime(2016, 02, 23, 20, 30, 52));
}
private void AddAppointment(string location, string body, string subject, DateTime startdatum, DateTime einddatum)
{
try
{
var AppOutlook = new Outlook.Application();

Outlook.AppointmentItem newAppointment =
(Outlook.AppointmentItem)
AppOutlook.CreateItem(Outlook.OlItemType.olAppointmentItem);
newAppointment.Start = startdatum;
newAppointment.End = einddatum;
newAppointment.Location = location;
newAppointment.Body = body;
newAppointment.BusyStatus=Outlook.OlBusyStatus.olTentative;
newAppointment.AllDayEvent = true;
newAppointment.Subject = subject;
newAppointment.Save();
newAppointment.Display(true);
}
catch (Exception ex)
{
MessageBox.Show("The following error occurred: " + ex.Message);
}
}

PS:对不起,如果我的英语不是很好。

最佳答案

我使用了 EWS api ( https://msdn.microsoft.com/en-us/library/office/dd633710(v=exchg.80).aspx )

我使用的代码是:

try
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.UseDefaultCredentials = true;
service.Credentials = new WebCredentials("user@domain.com", "password");
service.Url = new Uri("https://mail.domain.com/EWS/Exchange.asmx");
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "user2@domain.com");




Appointment appointment = new Appointment(service);
// Set the properties on the appointment object to create the appointment.
appointment.Subject = "Tennis lesson";
appointment.Body = "Focus on backhand this week.";
appointment.Start = DateTime.Now.AddDays(2);
appointment.End = appointment.Start.AddHours(1);
appointment.Location = "Tennis club";
appointment.ReminderDueBy = DateTime.Now;

// Save the appointment to your calendar.
appointment.Save(SendInvitationsMode.SendToNone);

// Verify that the appointment was created by using the appointment's item ID.
Item item = Item.Bind(service, appointment.Id, new PropertySet(ItemSchema.Subject));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

关于c# - 使用 C# 在其他人的 outlook 日历中创建约会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35574934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com