php-ews如何在发送电子邮件时设置重要性

时间:2013-03-26 14:15:16

标签: exchangewebservices php-ews

我使用php-ews发送邮件,但我找不到设置邮件重要性(优先级)的方法。 这是我的代码:



    $from = $mail['from'];
    $to = $mail['to'];
    $subject = $mail['subject'];
    $body = $mail['body'];

    $msg = new EWSType_MessageType();
    if($to && count($to) > 0){
        $toAddresses = $this->getAddresses($to);
        $msg->ToRecipients = $toAddresses;
    }

    $fromAddress = new EWSType_EmailAddressType();
    $fromAddress->EmailAddress = $from['mail'];
    $fromAddress->Name = $from['name'];

    $msg->From = new EWSType_SingleRecipientType();
    $msg->From->Mailbox = $fromAddress;

    $msg->Subject = $subject;

    $msg->Body = new EWSType_BodyType();
    $msg->Body->BodyType = 'HTML';
    $msg->Body->_ = $body;

    $msgRequest = new EWSType_CreateItemType();
    $msgRequest->Items = new EWSType_NonEmptyArrayOfAllItemsType();

    $msgRequest->Items->Message = $msg;
    $msgRequest->MessageDisposition = 'SendAndSaveCopy';
    $msgRequest->MessageDispositionSpecified = true;

    $response = $this->ews->CreateItem($msgRequest);
    return $response;

提前感谢您的回复!

2 个答案:

答案 0 :(得分:1)

您需要加载EWSType_ImportanceChoicesType类。您的代码应如下所示:

$from = $mail['from'];
$to = $mail['to'];
$subject = $mail['subject'];
$body = $mail['body'];

$msg = new EWSType_MessageType();
if($to && count($to) > 0){
    $toAddresses = $this->getAddresses($to);
    $msg->ToRecipients = $toAddresses;
}

$fromAddress = new EWSType_EmailAddressType();
$fromAddress->EmailAddress = $from['mail'];
$fromAddress->Name = $from['name'];

$msg->From = new EWSType_SingleRecipientType();
$msg->From->Mailbox = $fromAddress;

$msg->Subject = $subject;

$msg->Body = new EWSType_BodyType();
$msg->Body->BodyType = 'HTML';
$msg->Body->_ = $body;

$msgRequest = new EWSType_CreateItemType();
$msgRequest->Items = new EWSType_NonEmptyArrayOfAllItemsType();

$msgRequest->Items->Message = $msg;
// Start importance code
$msgRequest->Items->Message->Importance = new EWSType_ImportanceChoicesType();
$msgRequest->Items->Message->Importance->_ = EWSType_ImportanceChoicesType::HIGH;
// End importance code
$msgRequest->MessageDisposition = 'SendAndSaveCopy';
$msgRequest->MessageDispositionSpecified = true;

$response = $this->ews->CreateItem($msgRequest);
return $response;

要更改重要性,只需将以下行的结尾更改为HIGH,LOW或NORMAL:

$msgRequest->Items->Message->Importance->_ = EWSType_ImportanceChoicesType::HIGH;

答案 1 :(得分:0)

我不熟悉php,但如果我使用C#,mailmessage-class有一个“重要性”属性,它是一个枚举,可以设置为:High,Low和Normal。默认为“正常”。

希望这可以帮助你...