Tuesday, October 13, 2009

Sending meeting request through Exchange server API

Here we can send a meeting request through exchange server .

Here is the code for creating the  meeting request.

        ExchangeService exchangeService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);

        exchangeService.Credentials = new WebCredentials("<user name>", "<password>", "<domain>");

        exchangeService.Url = new Uri("<Exchange server url.>");

 

Here is the method in C#  which creates the meeting request.

public static void CreateMeetingRequest(string ownerEmail, string subjectText, string messageBody, string location, DateTime start, DateTime end, DataTable attendees)

        {

            try

            {

                SPSecurity.RunWithElevatedPrivileges(delegate()

                {

                    ExchangeService exchangeService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);

                    exchangeService.Credentials = new WebCredentials(EXCHANGE_USER_NAME, EXCHANGE_PASSWORD, EXCHANGE_DOMAIN);

                    exchangeService.Url = new Uri(EXCHANGE_URL);

                    Appointment appointment = new Appointment(exchangeService);

                    appointment.Subject = subjectText;

                    appointment.Body = new MessageBody(BodyType.Text, messageBody);

                    appointment.Start = start;

                    appointment.End = end;

                    appointment.Location = location;

                    appointment.ReminderMinutesBeforeStart = 30;

                    foreach (DataRow drow in attendees.Rows)

                    {

                        appointment.RequiredAttendees.Add(new Attendee(Convert.ToString(drow["Email"])));

                    }

                    appointment.Save();

                });

            }

            catch (ServiceRequestException ex)

            {

                throw new ApplicationException("Error: " + ex.Message);

            }

            catch (WebException ex)

            {

                throw new ApplicationException("Error: " + ex.Message);

            }

        }

No comments:

Post a Comment