inserting outlook appointment using c#, asp.net

2020-03-26 08:53发布

问题:

Im looking to insert an appointment in a users calendar, I can easliy insert in my own using Microsoft.Office.Interop.Outlook.Application (below), then add the user as a recipient, but what if I dont want to add myself, if I only want to add others? Can this be done in a similar way?

thanks

            Microsoft.Office.Interop.Outlook.Application app = null; 
            Microsoft.Office.Interop.Outlook.AppointmentItem appt = null; 
            app = new Microsoft.Office.Interop.Outlook.Application(); 

            appt = (Microsoft.Office.Interop.Outlook.AppointmentItem)app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem); 
            appt.Subject = "Meeting "; 
            appt.Body = "Test"; 
            appt.Location = "a room"; 
            appt.Start = Convert.ToDateTime("08/08/2012 05:00:00 PM"); 
            appt.Recipients.Add("a@b.com"); 
            appt.End = Convert.ToDateTime("08/08/2012 6:00:00 PM"); 
            appt.ReminderSet = true; 
            appt.ReminderMinutesBeforeStart = 15; 
            appt.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh; 
            appt.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olBusy; 
            appt.Save();

回答1:

You cannot (or should not) use the Outlook API from an ASP.NET application. Instead Exchange Server provides a Web Services SDK that allows you to interact with the Exchange Server. The documentation has a sample of how to create appointments in a user's mailbox.

You may have to delegate access to the user account used to execute the ASP.NET request to succesfully be able to interact with the Exchange Server API.

EWS was first introduced in Exchange 2007. For older versions of Exchange you can use Collaboration Data Objects (CDO). The Exchange 2003 SDK contains documentation on how to create appointments and meeting requests.