By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,558 Members | 1,399 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,558 IT Pros & Developers. It's quick & easy.

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

P: 2
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.
Mar 27 '06 #1
Share this Question
Share on Google+
6 Replies


P: 2
Option Explicit On
Option Strict On

Module Module1

Public Sub Main()

' Variables.
Dim PUTRequest As System.Net.HttpWebRequest
Dim PUTResponse As System.Net.HttpWebResponse
Dim MOVERequest As System.Net.HttpWebRequest
Dim MOVEResponse As System.Net.HttpWebResponse
Dim MyCredentialCache As System.Net.CredentialCache
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 PUTRequestStream As System.IO.Stream
Dim bytes() As Byte

Try
' Initialize variables.
strServer = "192.168.0.1"
strPassword = "-"
strDomain = "techdomain"
strAlias = "Administrator"
strTo = "testfolder@techdomain.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/" & "/##DavMailSubmissionURI##/"
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@example.com>" & vbNewLine & _
"MIME-Version: 1.0" & vbNewLine & _
"Content-Type: multipart/mixed;" & vbNewLine & _
" boundary = ""XXXXboundary 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.
MyCredentialCache = New System.Net.CredentialCache
MyCredentialCache.Add(New System.Uri(strMailboxURI), _
"NTLM", _
New System.Net.NetworkCredential(strAlias, strPassword, strDomain) _
)

' Create the PUT HttpWebRequest object.
PUTRequest = CType(System.Net.WebRequest.Create(strTempURI), _
System.Net.HttpWebRequest)

' Add the network credentials to the request.
PUTRequest.Credentials = MyCredentialCache

' Specify the PUT method.
PUTRequest.Method = "PUT"

' Encode the body using UTF-8.
bytes = System.Text.Encoding.UTF8.GetBytes(strBody)

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

' Get a reference to the request stream.
PUTRequestStream = PUTRequest.GetRequestStream()

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

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

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

' PUT the message in the Drafts folder of the
' sender's mailbox.
PUTResponse = CType(PUTRequest.GetResponse(), System.Net.HttpWebResponse)

Console.WriteLine("Message successfully PUT to " & strTempURI)

' Create the MOVE HttpWebRequest object.
MOVERequest = CType(System.Net.WebRequest.Create(strTempURI), _
System.Net.HttpWebRequest)

' Add the network credentials to the request.
MOVERequest.Credentials = MyCredentialCache

' Specify the MOVE method.
MOVERequest.Method = "MOVE"

' Set the Destination header to the
' mail submission URI.
MOVERequest.Headers.Add("Destination", strSubURI)

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

Console.WriteLine("Message successfully sent to " & strTo)

' Clean up.
PUTResponse.Close()
MOVEResponse.Close()

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.WriteLine(ex.Message)

End Try

End Sub

End Module
Mar 27 '06 #2

P: 1
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
Jul 25 '06 #3

P: 1
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.
Mar 19 '07 #4

P: 1
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!
Sep 1 '07 #5

P: 45
Use PROPPATCH instead of PUT. It will create an editable email that can edited in OWA by calling up the URL.
Jan 10 '08 #6

P: 2
I think that the solution given here might be what you are looking for:

http://www.independentsoft.de/webdav...ndmessage.html
Dec 16 '10 #7

Post your reply

Sign in to post your reply or Sign up for a free account.