Microsoft KB Archive/314188

= How to search for the URI property of a sender's e-mail submission and to send an e-mail message by using this property in Visual Basic .NET =

Article ID: 314188

Article Last Modified on 6/29/2007

-

APPLIES TO


 * Microsoft Exchange 2000 Server Standard Edition
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft XML Core Services 4.0
 * Microsoft XML Core Services 4.0

-



This article was previously published under Q314188



SUMMARY
This article describes how to use Microsoft XML 3.0 to search for the URI property of a sender's e-mail submission and to send an e-mail message by using this property in Microsoft Visual Basic .NET.



MORE INFORMATION
To use Microsoft XML 3.0 to search for the URI property of a sender's e-mail submission and to send an e-mail message by using this property in Visual Basic .NET, follow these steps.

Note This sample code uses Microsoft XML 3.0, but the information also applies to Microsoft XML 4.0.  Start Microsoft Visual Studio .NET. On the File menu, point to New, and then click Project. In the Visual Basic Projects list, click Console Application.

By default, the Module1.vb file is created. Add a reference to Microsoft XML 3.0. To do so, follow these steps:  On the Project menu, click Add Reference. Click the COM tab, click Microsoft XML v3.0, and then click Select. In the Add References dialog box, click OK.</li> If you are prompted to generate wrappers for the libraries that you selected, click Yes.</li></ol> </li>  In the code window, replace the existing code with the following: Imports System.Reflection

Module Module1 Sub Main 'TODO: Replace with the name of the computer that is running Microsoft Exchange 2000 Server. Dim strExchSvr As String = &quot;<ExchServerName>&quot;

'TODO: Replace with the alias of the sender. Dim strAlias As String = &quot;<UserAlias>&quot;

'TODO: Replace with the domain name and the alias of the sender. Dim strUserName As String = &quot;<UserDomain\UserAlias>&quot;

'TODO: Replace with the sender's password. Dim strPassWord As String = &quot;<UserPassword>&quot;

Dim sMailUrl As String sMailUrl = FindSubmissionURL(strExchSvr, strAlias, strUserName, strPassWord) If (sMailUrl <> &quot;&quot;) Then ' TODO: Replace with your mail information. Dim strFrom As String = &quot;from@example.com&quot; Dim strTo As String = &quot;to@example.com&quot; Dim strSubject As String = &quot;Send Using Webdav&quot; Dim strBody As String = &quot;Hello World&quot;

Dim oXMLHttp As MSXML2.XMLHTTP30 = New MSXML2.XMLHTTP30 oXMLHttp.open(&quot;PUT&quot;, sMailUrl, False, strUserName, strPassWord)

Dim mySentTime As DateTime = New DateTime Dim sQuery As String sQuery = &quot;From: &quot; & strFrom & vbNewLine & _ &quot;To: &quot; & strTo & vbNewLine & _ &quot;Subject: &quot; & strSubject & vbNewLine & _ &quot;Date: &quot; & Convert.ToDateTime(&quot;9/11/2001 11:45 AM&quot;) & vbNewLine & _ &quot;X-Mailer: My DAV mailer&quot; & vbNewLine & _ &quot;MIME-Version: 1.0&quot; & vbNewLine & _ &quot;Content-Type: text/plain&quot; & vbNewLine & _ &quot;Charset = &quot;&quot;iso-8859-1&quot;&quot;&quot; & vbNewLine & _ &quot;Content-Transfer-Encoding: 7bit&quot; & vbNewLine & vbNewLine & _ strBody

oXMLHttp.setRequestHeader(&quot;Translate&quot;, &quot;f&quot;) oXMLHttp.setRequestHeader(&quot;Content-Type&quot;, &quot;message/rfc822&quot;) oXMLHttp.setRequestHeader(&quot;Content-Length&quot;, &quot;&quot; & sQuery.Length)

oXMLHttp.send(sQuery)

Console.WriteLine(oXMLHttp.status) Console.WriteLine(oXMLHttp.statusText) Console.WriteLine(oXMLHttp.responseText)

oXMLHttp = Nothing End If   End Sub

Private Function FindSubmissionURL(ByVal strExchSvr As String, ByVal strAlias As String, ByVal strUserName As String, ByVal strPassWord As String) As String Dim query As String Dim strURL As String Dim baseName As String = &quot;&quot; Dim xmlReq As MSXML2.XMLHTTP30 = New MSXML2.XMLHTTP30

Dim xmldom As MSXML2.DOMDocument = New MSXML2.DOMDocument Dim xmlRoot As MSXML2.IXMLDOMElement Dim xmlNode As MSXML2.IXMLDOMNode

'Create the DAV PROPFIND request. strURL = &quot;http://&quot; & strExchSvr & &quot;/exchange/&quot; & strAlias

xmlReq.open(&quot;PROPFIND&quot;, strURL, False, strUserName, strPassWord) xmlReq.setRequestHeader(&quot;Content-Type&quot;, &quot;text/xml&quot;) xmlReq.setRequestHeader(&quot;Depth&quot;, &quot;0&quot;)

query = &quot;<?xml version='1.0'?>&quot; query = query & &quot;<a:propfind xmlns:a='DAV:'>&quot; query = query & &quot;<a:prop xmlns:m='urn:schemas:httpmail:'>&quot; query = query & &quot;<m:sendmsg/>&quot; query = query & &quot;</a:prop>&quot; query = query & &quot;</a:propfind>&quot;

xmlReq.send(query)

Console.WriteLine(xmlReq.status) Console.WriteLine(xmlReq.statusText) Console.WriteLine(xmlReq.responseText)

' Process the result. If xmlReq.status >= 200 And xmlReq.status < 300 Then

xmldom.loadXML(xmlReq.responseText) xmlRoot = xmldom.documentElement Dim i As Integer

For i = 1 To xmlRoot.attributes.length xmlNode = xmlRoot.attributes(i) If xmlNode.text = &quot;urn:schemas:httpmail:&quot; Then baseName = xmlNode.baseName Exit For End If           Next

xmlNode = xmlRoot.selectSingleNode(&quot;//&quot; & baseName & &quot;:sendmsg&quot;)

Return xmlNode.text Else Console.WriteLine(&quot;Cannot find mail submission URL&quot;) Return &quot;&quot; End If   End Function End Module </li> Search for the TODO text string in the code, and then modify the code for your environment.</li> Press the F5 key to build and to run the program.</li> Make sure that the e-mail message has been sent and received.</li></ol>

<div class="references_section">