473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
6 17068
ErwinF
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
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
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
Rerkah
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
zaidlig
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
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

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

Similar topics

11
by: Google Mike | last post by:
I've got RH9 Linux with default PHP. Is there a way to send email on Linux to an Exchange Server from PHP and/or other tools when there is *NOT* SMTP access? Has anyone figured out a way to...
0
by: Andrew Pasetti | last post by:
Hello, There is a document on msdn that describes how to send an email using webdav and vb.net...
1
by: Paul | last post by:
I am using a windows service which accesses Microsoft Outlook. Outlook is supposed to send an email. This works fine when not run in a windows service. I am running the service under my user...
1
by: Michele | last post by:
Hi, I need to send the same Email to different people. I'm using Outlook XP and VB.Net. I tryed with the following code: Dim oOutL As Outlook.Application Dim oMail As Outlook._MailItem oOutL...
8
by: John Brock | last post by:
I am currently using a VB.NET program to send out e-mails with plain text bodies (plus one attachment). The emails are being received as Rich Text messages (probably just my personal Outlook...
2
by: Robert Dufour | last post by:
I tried using (vs2003 Vb.Net) Public Sub SendEmail( _ ByVal Recipient As String, _ ByVal Sender As String, _ ByVal Subject As String, _ ByVal Message As String, _
2
by: Joe George | last post by:
Hi there, How to save email attachments, from exchange, using WebDAV in C#.NET? Sample code please................... Thanks for your help. -- Joe George
2
by: oyster | last post by:
I find that the existing email moudle is some hard for me to understand, especially the part of how to set the CC, BCC and attach the files. Is there any more easy one like this p-code? import...
1
by: Chitu03 | last post by:
Hi I am already send a mail using Php with some attachement into it. My Problem is the attachement file is in my Database(mysql). I don't know how can i get from database and then add to my mail....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.