信息
我已经运行了这个代码一年,一切正常,直到昨天。请参阅下面的错误消息该代码仅提取收件箱中未读电子邮件的数量。在增加的数量中,它还将在运行代码的客户端上发出声音。我的Exchange服务器正在运行 Exchange Server 2013 CU12 ,但它一直在使用 ExchangeWebServices :: VERSION_2010 (请参阅代码bolow)。
错误消息
致命错误:未捕获的SoapFault异常:[客户]类' EWS_Exception'在/var/www/html/php-ews/NTLMSoapClient.php:87中找不到堆栈跟踪:#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 {在第87行的/var/www/html/php-ews/NTLMSoapClient.php中抛出
我的代码基于此处的代码: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>';
}
}
过了一段时间,我以为代码可能会停止工作&#34;喜欢&#34; VERSION_2010因为服务器是2013 CU12。我尝试了以下解决方案,但它没有奏效:https://github.com/jamesiarmes/php-ews/issues/195
有谁知道如何解决这个问题?它有点令人沮丧,因为代码工作了一年,现在它没有。服务器端没有任何改变。
提前致谢。
答案 0 :(得分: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>