Howto Add an Attachment with Webdav


There is no mechanism to add an attachment in WebDAV.  You will need to create/recreate the item using a WebDAV PUT.  The text you would be putting would be the mime of the item, which also contains the attachment. It’s useful here to use CDOSYS to create a message and add an attachment – then extract the MIME from the message and use it for the WEBDAV PUT.  You will need a header of "translate" set to "f".


 


If the message already exists, you will need to, you must do a GET on the message stream, which will give you the message + attachments in a string.  Next, modify the stream to include a new attachment.  After this, the string can be used in a PUT statement to write the attachment.

Comments (5)

  1. Antonino Di Bella says:

    Hi Daniel,

    I have read many of your posts, for me, your posts are very important…

    But now i’m blocked…

    I know that you are GURU in exchange WEBDav protocol and i want make a question for you and hope that you can help me.

    I have a php class (based on http://www.troywolf.com/articles/php/exchange_webdav_examples.php) for communicate with exchange webdav protocol…I can get emails,appointments, attachments but now i have a problem.

    I want attach a file in a email.

    I create the mail in draft box folder, now how can attach a file in the email?, i try with the PUT command…but don’t work…

    Can you explain me the correct way?

    I create the normal PUT request with the file in the body of the request, but this don’t attach the file in the email…

    Thanks for your answer,

    kind regards, Antonino (sorry for my bad english)

  2. Webdav101 says:

    Hello Antonio;

    You will need to do a put with the entire message in MIME format.  The entire message will include the full message body, recipients, subjet, etc PLUS each of the attachments as body parts of that message.  You can use CDOSYS to create a message with attachments and then have CDOSYS generate MIME which will be used with a PUT – there should be a sample on this in my blog.   You cannot do a PUT of an attachment by itself – you have to do the PUT with the entire message (message body, headers, recipients, attachments) in mime format.  

    Thanks,

    Dan

  3. Antonino Di Bella says:

    Thanks for your fast response….

    you know some links, tutorials or something for use the cdosys with php…

    I’m searching on Google, i found a lot of tutorial to use cdosys in asp or generally .net languages but nothing with PHP…

    (A my think….)

    If i make a mime message, can i put this message such as an EML file in exchange draft folder and after with MOVE command, move this file in ##DavMailSubmissionURI## ?

    Many thanks, Antonino

  4. Webdav101 says:

    Hello Antonino;

    You probably will not find many (if any) samples of PHP using CDOSYS.  

    The best way to send a message with WebDAV is to do the following:

     1) Create a MIME message as a string.  This MIME string should contain the full body and attachments. This can be done with CDOSYS, with a third-party API or programatically by programming against the MIME RFCs.

     2) Do a PUT using this string into the "drafts" folder.  Be sure to use a unique name.  The message should always be created in the drafts folder initally and not the ##DavMailSubmissionURI## folder. If you create the message in the ##DavMailSubmissionURI## first, it will be sent right away and may not be constructed propery.

     3) You may need to do a PROPPATCH to add additional properties to the message which cannot be set via MIME.  What would need to be set depends upon what you are doing.  In most cases, you will not need to do a PROPPATCH.

     4) At this time your message should be completely built.  The next step is to do a WebDAV MOVE on the message to move it from the "drafts" folder to the ##DavMailSubmissionURI## folder.

    Thanks,

    Dan

  5. Antonino Di Bella says:

    ^__^ how can I thank you?

    is what I wanted to know.

    You are my hero

    I’m very happy, my job can proceed…

    I’m serious, MANY MANY THANKS

Skip to main content