0

我已经使用 php-ews 一个月了,我可以开会,但我希望组织者是我参加会议的房间电子邮件/房间名称

例如,我在上午 8:00 - 上午 10:00 在房间 1 (room1@mydomain.com) 创建一个会议,我希望组织者是房间电子邮件 (room1@mydomain.com) / 房间名称 (room1)

我知道我可以在 Office 365 中执行此操作(使用我的凭据登录 -> 选择打开另一个邮箱 -> 选择 room1@mydomain.com),但我想通过 php-ews 执行此操作

我已经将资源邮箱、邮箱委托属性设置为我的登录凭据

是否可以将组织者名称更改为房间名称/房间电子邮件?

我的基本代码:

$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);
}
4

1 回答 1

0

我最近不得不做同样的事情。当我搜索时,我在 Exchange SDK Docs 中找到了答案:

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

只需进行一些更改,我就能够使其在 php-ews 结构上工作。基本上,您将房间设置为一个可区分的文件夹并将其用作已保存的项目文件夹 ID。以用户身份登录的人必须具有房间的Delegate权限,它会自动代表房间发送用户的请求,房间将成为组织者。

// 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();
于 2018-07-16T17:53:53.717 回答