how to send email attachments using WebDAV coding in VB .NET?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ErwinF
    New Member
    • Mar 2006
    • 2

    how to send email attachments using WebDAV coding in VB .NET?

    Hi there,

    I would like to know the following:

    How to send send email attachments using WebDAV in VB .NET? Sample code please......... ..........

    Thanks for your help.
  • ErwinF
    New Member
    • Mar 2006
    • 2

    #2
    I found this........... ...

    Option Explicit On
    Option Strict On

    Module Module1

    Public Sub Main()

    ' Variables.
    Dim PUTRequest As System.Net.Http WebRequest
    Dim PUTResponse As System.Net.Http WebResponse
    Dim MOVERequest As System.Net.Http WebRequest
    Dim MOVEResponse As System.Net.Http WebResponse
    Dim MyCredentialCac he As System.Net.Cred entialCache
    Dim strMailboxURI As String
    Dim strSubURI As String
    Dim strTempURI As String
    Dim strServer As String
    Dim strPassword As String
    Dim strDomain As String
    Dim strAlias As String
    Dim strTo As String
    Dim strSubject As String
    Dim strText As String
    Dim strBody As String
    Dim PUTRequestStrea m As System.IO.Strea m
    Dim bytes() As Byte

    Try
    ' Initialize variables.
    strServer = "192.168.0. 1"
    strPassword = "-"
    strDomain = "techdomain "
    strAlias = "Administra tor"
    strTo = "testfolder@tec hdomain.com"
    strSubject = "WebDAV message test"
    strText = "This message was sent using WebDAV"

    ' Build the mailbox URI.
    strMailboxURI = "http://" & strServer & "/public/testfolder/"

    ' Build the submission URI for the message. If Secure
    ' Sockets Layer (SSL) is set up on the server, use
    ' "https://" instead of "http://".
    'strSubURI = "http://" & strServer & "/public/testfolder/" & "/##DavMailSubmis sionURI##/"
    strSubURI = "http://" & strServer & "/public/testfolder/" & "123/Test.eml"

    ' Build the temporary URI for the message. If SSL is set
    ' up on the server, use "https://" instead of "http://".
    strTempURI = "http://" & strServer & "/public/testfolder/" & _
    strSubject & ".eml"

    ' Construct the RFC 822 formatted body of the PUT request.
    ' Note: If the From: header is included here,
    ' the MOVE method request will return a
    ' 403 (Forbidden) status. The From address will
    ' be generated by the Exchange server.

    strBody = "From: Some One <someone@exampl e.com>" & vbNewLine & _
    "MIME-Version: 1.0" & vbNewLine & _
    "Content-Type: multipart/mixed;" & vbNewLine & _
    " boundary = ""XXXXbound ary text""" & vbNewLine & _
    vbNewLine & _
    "This is a multipart message in MIME format." & vbNewLine & _
    vbNewLine & _
    "--XXXXboundary text" & vbNewLine & _
    "Content-Type: text/plain" & vbNewLine & _
    vbNewLine & _
    "this is the body text 2" & vbNewLine & _
    vbNewLine & _
    "--XXXXboundary text" & vbNewLine & _
    "Content-Type: text/plain;" & vbNewLine & _
    "Content-Disposition: attachment;" & vbNewLine & _
    " filename = ""test.txt" "" & vbNewLine & _
    vbNewLine & _
    "this is the attachment text" & vbNewLine & _
    vbNewLine & _
    "--XXXXboundary text--" & vbNewLine

    ' Create a new CredentialCache object and fill it with the network
    ' credentials required to access the server.
    MyCredentialCac he = New System.Net.Cred entialCache
    MyCredentialCac he.Add(New System.Uri(strM ailboxURI), _
    "NTLM", _
    New System.Net.Netw orkCredential(s trAlias, strPassword, strDomain) _
    )

    ' Create the PUT HttpWebRequest object.
    PUTRequest = CType(System.Ne t.WebRequest.Cr eate(strTempURI ), _
    System.Net.Http WebRequest)

    ' Add the network credentials to the request.
    PUTRequest.Cred entials = MyCredentialCac he

    ' Specify the PUT method.
    PUTRequest.Meth od = "PUT"

    ' Encode the body using UTF-8.
    bytes = System.Text.Enc oding.UTF8.GetB ytes(strBody)

    ' Set the content header length. This must be
    ' done before writing data to the request stream.
    PUTRequest.Cont entLength = bytes.Length

    ' Get a reference to the request stream.
    PUTRequestStrea m = PUTRequest.GetR equestStream()

    ' Write the message body to the request stream.
    PUTRequestStrea m.Write(bytes, 0, bytes.Length)

    ' Close the Stream object to release the connection
    ' for further use.
    PUTRequestStrea m.Close()

    ' Set the Content-Type header to the RFC 822 message format.
    PUTRequest.Cont entType = "message/rfc822"

    ' PUT the message in the Drafts folder of the
    ' sender's mailbox.
    PUTResponse = CType(PUTReques t.GetResponse() , System.Net.Http WebResponse)

    Console.WriteLi ne("Message successfully PUT to " & strTempURI)

    ' Create the MOVE HttpWebRequest object.
    MOVERequest = CType(System.Ne t.WebRequest.Cr eate(strTempURI ), _
    System.Net.Http WebRequest)

    ' Add the network credentials to the request.
    MOVERequest.Cre dentials = MyCredentialCac he

    ' Specify the MOVE method.
    MOVERequest.Met hod = "MOVE"

    ' Set the Destination header to the
    ' mail submission URI.
    MOVERequest.Hea ders.Add("Desti nation", strSubURI)

    ' Send the message by moving it from the Drafts folder of the
    ' sender's mailbox to the mail submission URI.
    MOVEResponse = CType(MOVEReque st.GetResponse( ), System.Net.Http WebResponse)

    Console.WriteLi ne("Message successfully sent to " & strTo)

    ' Clean up.
    PUTResponse.Clo se()
    MOVEResponse.Cl ose()

    Catch ex As Exception

    ' Catch any exceptions. Any error codes from the PUT
    ' or MOVE method requests on the server will be caught
    ' here, also.
    Console.WriteLi ne(ex.Message)

    End Try

    End Sub

    End Module
    Last edited by ErwinF; Mar 27 '06, 10:29 PM. Reason: Update

    Comment

    • funnycoder
      New Member
      • Jul 2006
      • 1

      #3
      Hello,

      I'm trying to create a draft email using WEBDAV on the exchange server but when I view the message in OWA it shows that it has been already sent and I cannot edit the draft.

      Does anyone know why it appears as already sent? How can I fix it so that the draft message shows as unsent so I can edit the draft in OWA?

      Thanks

      Comment

      • anjalisharma
        New Member
        • Mar 2007
        • 1

        #4
        Originally posted by funnycoder
        Hello,

        I'm trying to create a draft email using WEBDAV on the exchange server but when I view the message in OWA it shows that it has been already sent and I cannot edit the draft.

        Does anyone know why it appears as already sent? How can I fix it so that the draft message shows as unsent so I can edit the draft in OWA?

        Thanks
        After getting response from the put request donot create the move request object. The move request sends the email.

        Comment

        • Rerkah
          New Member
          • Sep 2007
          • 1

          #5
          Originally posted by funnycoder
          Hello,

          I'm trying to create a draft email using WEBDAV on the exchange server but when I view the message in OWA it shows that it has been already sent and I cannot edit the draft.

          Does anyone know why it appears as already sent? How can I fix it so that the draft message shows as unsent so I can edit the draft in OWA?

          Thanks
          Did you ever get this to work? One person suggested not doing the move request, but this still leaves the message uneditable in your DRAFTS folder. I'm also trying to put a message in the DRAFTS folder that is editable for someone to manually send. Any help would be great, thanks!

          Comment

          • zaidlig
            New Member
            • Jan 2008
            • 45

            #6
            Use PROPPATCH instead of PUT. It will create an editable email that can edited in OWA by calling up the URL.

            Comment

            • AnaSimjanoski
              New Member
              • Dec 2010
              • 2

              #7
              I think that the solution given here might be what you are looking for:

              Comment

              Working...