1

信息

我已经运行这个代码一年了,直到昨天一切正常。请参阅下面的错误消息。该代码确实只获取收件箱中未读电子邮件的数量。在数量增加中,它还会在运行代码的客户端上播放声音。我的 Exchange 服务器正在运行Exchange Server 2013 CU12,但它一直在使用ExchangeWebServices::VERSION_2010(请参阅下面的代码)。

错误信息

致命错误:未捕获的 SoapFault 异常:[Client] Class 'EWS_Exception' not found in /var/www/html/php-ews/NTLMSoapClient.php:87 Stack trace: #0 /var/www/html/php-ews/NTLMSoapClient .php(87): NTLMSoapClient::__doRequest() #1 [内部函数]: NTLMSoapClient->__doRequest('https://mail.se...', ' http://schemas ....', 1 , 0) #2 /var/www/html/php-ews/ExchangeWebServices.php(552): SoapClient->__call('FindItem', Array) #3 /var/www/html/php-ews/ExchangeWebServices.php (552): NTLMSoapClient_Exchange->FindItem(Object(EWSType_FindItemType)) #4 /var/www/html/mail.php(104): ExchangeWebServices->FindItem(Object(EWSType_FindItemType)) #5 {main} 抛出 /var/ www/html/php-ews/NTLMSoapClient.php 第 87 行

我的代码基于此处找到的代码:http: //litphp.info/want_to_print_unread_mail_body_and_subject_using_ews_from_exchange_server_in_php

我的代码

function __autoload($class_name)
{
    // Start from the base path and determine the location from the class name,
    $base_path = 'php-ews';
    $include_file = $base_path . '/' . str_replace('_', '/', $class_name) . '.php';

    return (file_exists($include_file) ? require_once $include_file : false);
}

$ews = new ExchangeWebServices("mail.server.path.com", $mailuser, $mailpass, ExchangeWebServices::VERSION_2010);

$request = new EWSType_FindItemType();
$itemProperties = new EWSType_ItemResponseShapeType();
$itemProperties->BaseShape = EWSType_DefaultShapeNamesType::ID_ONLY;
$itemProperties->BodyType = EWSType_BodyTypeResponseType::BEST;
$request->ItemShape = $itemProperties;

$fieldType = new EWSType_PathToUnindexedFieldType();
$fieldType->FieldURI = 'message:IsRead';

$constant = new EWSType_FieldURIOrConstantType();
$constant->Constant = new EWSType_ConstantValueType();
$constant->Constant->Value = "0";

$IsEqTo = new EWSType_IsEqualToType();
$IsEqTo->FieldURIOrConstant = $constant;
$IsEqTo->Path = $fieldType;

$request->Restriction = new EWSType_RestrictionType();
$request->Restriction->IsEqualTo = new EWSType_IsEqualToType();
$request->Restriction->IsEqualTo->FieldURI = $fieldType;
$request->Restriction->IsEqualTo->FieldURIOrConstant = $constant;

$request->IndexedPageItemView = new EWSType_IndexedPageViewType();
$request->IndexedPageItemView->BasePoint = 'Beginning';
$request->IndexedPageItemView->Offset = 0;

$request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Mailbox = new StdClass;
$request->ParentFolderIds->DistinguishedFolderId->Mailbox->EmailAddress = 'emailaddress@test.com';
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::INBOX;

$request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW;

$result = new EWSType_FindItemResponseMessageType();
$result = $ews->FindItem($request);

if ($result->ResponseMessages->FindItemResponseMessage->ResponseCode == 'NoError' && $result->ResponseMessages->FindItemResponseMessage->ResponseClass == 'Success'){

    // Need this variable to check for the new value.
    $count_new = $result->ResponseMessages->FindItemResponseMessage->RootFolder->TotalItemsInView;

    // Play sound if value has increased.
    if($_SESSION['count_previous'] < $count_new) {
        echo '<script type="text/javascript">play_sound();</script>';
    }

    // Saving the value for later usage.
    $count = $result->ResponseMessages->FindItemResponseMessage->RootFolder->TotalItemsInView;

    // Saving the current count to a session. Need it to compair with the new value ($count_new).
    $_SESSION['count_previous'] = $count;

    if($count > 0) {
        echo '<script type="text/javascript">document.body.style.backgroundColor = "#fc2828";</script>';
        echo "<h1>" . $count . "</h1><br>";
        echo '<img src="img/mail.png" height="165px">';
    } else {
        echo '<h1 class="paddingH12 test">No mail</h1>';
    }

}

过了一会儿,我认为可能是因为服务器是 2013 CU12,所以代码停止“像”VERSION_2010 一样工作。我尝试了以下解决方案,但没有奏效:https ://github.com/jamesiarmes/php-ews/issues/195

有谁知道如何解决这个问题?这有点令人沮丧,因为代码工作了一年,但现在不行了。服务器端没有任何改变。

提前致谢。

4

1 回答 1

0

很抱歉这篇文章。它现在又开始工作了。我不知道是什么问题。Exchange 服务器或网络上的负载可能很高。随意使用此代码仅获取未读电子邮件。

我也在 60 秒后刷新页面(否则声音不起作用):

<meta http-equiv="refresh" content="60">

用于声音的 JavaScript(在标题中):

<script type="text/javascript">
    function play_sound() {
        var audioElement = document.createElement('audio');
        audioElement.setAttribute('src', '/sound/mail.mp3');
        audioElement.setAttribute('autoplay', 'autoplay');
        audioElement.load();
        audioElement.play();
    }
</script>
于 2016-04-29T10:17:12.000 回答