开发者

EWS - php sending email with attachment

I'm new to using EWS from Exchangeclient classes.

I'm looking for a simple example how to send an email with an attachment. I've found examples about how to send an email but not sending an email with an attachment.

This is my script:

$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;
    }

}


You have to first save the email as a draft (with the appropriate message disposition), then CreateAttachment() so it has an attachment, then edit it with UpdateItem() so the message disposition is SendOnly. Then it will be sent.

See David Sterling's reply on this thread: http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/f7d5257e-ec98-40fd-b301-f378ba3080fd/ (It's about Meeting Requests but they work the same way.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜