我一直在使用php-ews一个月,我能够开会,但我希望组织者是我参加会议的房间电子邮件/房间名称
所以例如,我在上午8:00 - 上午10:00在room1(room1@mydomain.com)创建会议,我希望组织者是房间电子邮件(room1@mydomain.com)/房间名称(room1)
我知道我可以在办公室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);
}
答案 0 :(得分:0)
我最近不得不做同样的事情。在搜索时,我在Exchange SDK文档中找到了答案:
仅进行了一些更改,就可以使其在php-ews结构上运行。 基本上,您将房间作为一个区别文件夹,并将其用作保存的项目文件夹ID。以用户身份登录的用户必须具有对该会议室的“代理”访问权限,它将自动代表该会议室发送来自用户的请求,该会议室将成为组织者。
// 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();