0
votes

I've been using php-ews for a month, i able to make a meeting but i want the organizer is the room email / room name that i attend the meeting

so for example, i create a meeting at 8:00am - 10:00am at room1 ([email protected]), i want the organizer is the room email ([email protected]) / room name (room1)

i know i can do this in the office 365 (login with my credential ->choose open another mailbox -> choose [email protected]), but i want to do this via php-ews

i already set the resource mailbox, mailbox delegation property to my login credential

is it possible to change the organizer name to room name / room email??

my basic code:

$host = $selected_exchange->exchange_host;
$username = $exchange_email;
$password = $exchange_password;
$version = $selected_exchange->exchange_version;
$timezone = 'SE Asia Standard Time';

$client = new Client($host, $username, $password, $version);
$client->setTimezone($timezone);

$start = new DateTime($booking_date . $booking_time_start . ":00");
$end = new DateTime($booking_date . $booking_time_end);
$guests = array(
    array(
    'name' => $room->exchange_room_name,
    'email' => $room->exchange_room_email,
    )
);
// Set connection information.

$request = new CreateItemType();
$request->SendMeetingInvitations = 'SendOnlyToAll'; 
//CalendarItemCreateOrDeleteOperationType::SEND_ONLY_TO_ALL;
$request->Items = new NonEmptyArrayOfAllItemsType();

// Build the event to be added.
$event = new CalendarItemType();
$event->RequiredAttendees = new NonEmptyArrayOfAttendeesType();
$event->Start = $start->format('c');
$event->End = $end->format('c');
$event->Subject = $meeting_title;
$event->Location = $room->exchange_room_name;

// Set the event body.
$event->Body = new BodyType();
$event->Body->_ = $special_request . " Meeting Created By: ";
$event->Body->BodyType = 'Text'; //BodyTypeType::TEXT;

// Iterate over the guests, adding each as an attendee to the request.
foreach ($guests as $guest) {
    $attendee = new AttendeeType();
    $attendee->Mailbox = new EmailAddressType();
    $attendee->Mailbox->EmailAddress = $guest['email'];
    $attendee->Mailbox->Name = $guest['name'];
    $attendee->Mailbox->RoutingType = 'SMTP'; //RoutingType::SMTP;
    $event->RequiredAttendees->Attendee[] = $attendee;
}

try
{
    // Add the event to the request. You could add multiple events to create more
    // than one in a single request.
    $request->Items->CalendarItem[] = $event;
    $response = $client->CreateItem($request);

    // Iterate over the results, printing any error messages or event ids.
    $response_messages = $response->ResponseMessages->CreateItemResponseMessage;
    foreach ($response_messages as $response_message) {
        // Make sure the request succeeded.
        if ($response_message->ResponseClass != ResponseClassType::SUCCESS) {
            $code = $response_message->ResponseCode;
            $message = $response_message->MessageText;
            //fwrite(STDERR, "Event failed to create with \"$code: $message\"\n");
            $result = array('ok' => 0, 'message' => $message);
            continue;
        }
        // Iterate over the created events, printing the id for each.
        foreach ($response_message->Items->CalendarItem as $item) {
            $id = $item->ItemId->Id;
            //fwrite(STDOUT, "Created event $id\n");
            $result = array('ok' => 1, 'message' => 'Success Added To Calendar');
        }
    }
}
catch(Exception $e)
{
    $result = array('ok' => 0, 'message' => $message);
}
1

1 Answers

0
votes

I recently had to do this same thing. When I was searching, I found the answer within the Exchange SDK Docs :

https://docs.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2007/bb856541%28v%3dexchg.80%29

With only a few changes, I was able to make it work on the php-ews structure. Basically you make the room as a distinguished folder and use it as the saved item folder id. The person who is logged in as the user must have Delegate access to the room, and it will automatically send the request from the user on behalf of the room, and the room will be the organizer.

// Set connection information with save copy so that it saves to the folder
$request = new CreateItemType();
$request->MessageDisposition = MessageDispositionType::SEND_AND_SAVE_COPY;
$request->SendMeetingInvitations = CalendarItemCreateOrDeleteOperationType::SEND_TO_ALL_AND_SAVE_COPY;

// Add the Room as the target saved item folder (user must have delagate access to the room)
$roomFolder = new DistinguishedFolderIdType();
$roomFolder->Id = DistinguishedFolderIdNameType::CALENDAR;
$roomFolder->Mailbox = new EmailAddressType();
$roomFolder->Mailbox->EmailAddress = $room->exchange_room_email;
$roomFolder->Mailbox->Name = $room->exchange_room_name;
$target = new TargetFolderIdType();
$target->DistinguishedFolderId = $roomFolder;
$request->SavedItemFolderId = $target;

$request->Items = new NonEmptyArrayOfAllItemsType();