EWS - php发送带附件的电子邮件

时间:2011-06-06 10:37:17

标签: php exchangewebservices nusoap exchange-server-2007

我刚接触使用Exchangeclient类中的EWS。

我正在寻找一个简单的示例,说明如何发送带附件的电子邮件。我找到了有关如何发送电子邮件但未发送带附件的电子邮件的示例。

这是我的剧本:

$exchangeclient = new Exchangeclient();
$exchangeclient->init($username, $password, NULL, 'ews/Services.wsdl');
$exchangeclient->send_message($mail_from, $subject, $body, 'HTML', true, true);

function - PHP Classes:

    function send_message($to, $subject, $content, $bodytype="Text", $saveinsent=true, $markasread=true) {
    $this->setup();

    if($saveinsent) {
        $CreateItem->MessageDisposition = "SendOnly";
        $CreateItem->SavedItemFolderId->DistinguishedFolderId->Id = "sentitems";
    }
    else
        $CreateItem->MessageDisposition = "SendOnly";

    $CreateItem->Items->Message->ItemClass = "IPM.Note";
    $CreateItem->Items->Message->Subject = $subject;
    $CreateItem->Items->Message->Body->BodyType = $bodytype;
    $CreateItem->Items->Message->Body->_ = $content;
    $CreateItem->Items->Message->ToRecipients->Mailbox->EmailAddress = $to;

    if($markasread)
        $CreateItem->Items->Message->IsRead = "true";

    $response = $this->client->CreateItem($CreateItem);

    $this->teardown();

    if($response->ResponseMessages->CreateItemResponseMessage->ResponseCode == "NoError")
        return true;
    else {
        $this->lastError = $response->ResponseMessages->CreateItemResponseMessage->ResponseCode;
        return false;
    }

}

1 个答案:

答案 0 :(得分:1)

您必须先将电子邮件保存为草稿(使用相应的消息处理),然后将CreateAttachment()保存为附件,然后使用UpdateItem()对其进行编辑,以便消息处置为SendOnly。然后它将被发送。

请参阅David Sterling对此主题的回复:http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/f7d5257e-ec98-40fd-b301-f378ba3080fd/(这是关于会议请求,但它们的工作方式相同。)