Microsoft KB Archive/310292

= How to send an e-mail message by using the SubmissionURL property of the sender and Visual C# =

Article ID: 310292

Article Last Modified on 12/11/2006

-

APPLIES TO


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

-



This article was previously published under Q310292



SUMMARY
This article describes how to use Microsoft XML 3.0 to search for a sender's SubmissionURL property and then to send an e-mail message in Microsoft Visual C#.



MORE INFORMATION
To search for a sender's SubmissionURL property and then to send an e-mail message, follow these steps:  Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005. On the File menu, point to New, and then click Project. In the Visual C# Projects types list, click Console Application.

Note In Visual Studio 2005, click Visual C# in the Visual C# Projects types list.

In Visual Studio .NET, Class1.cs is created by default. In Visual Studio 2005, Program.cs is created by default. 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, locate Microsoft XML v3.0, and then click Select.

Note In Visual Studio 2005, you do not have to 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 code with the following: using System; using System.Reflection;

namespace WebDav {   class Class1 {          public static void Main(String [] args) {           try {               // TODO: String strExchSvr = &quot;ExchServer&quot;; String strAlias = &quot;UsrAlias&quot;; String strUserName = @&quot;UsrDom\UsrAlias&quot;; String strPassWord = &quot;UsrPassword&quot;; Class1 Instmyclass = new Class1; String sMailUrl; sMailUrl = Instmyclass.FindSubmissionURL(strExchSvr, strAlias, strUserName, strPassWord); // TODO: String strFrom = &quot;usr1@example.com&quot;; String strTo = &quot;usr2@example.com&quot;; String strSubject = &quot;Send Using Webdav&quot;; String strBody = &quot;Hello World&quot;;

MSXML2.XMLHTTP30 oXMLHttp = new MSXML2.XMLHTTP30; oXMLHttp.open(&quot;PUT&quot;, sMailUrl, false, strUserName, strPassWord); DateTime mySentTime = new DateTime; String sQuery; sQuery = &quot;From: &quot; + strFrom + &quot;\n&quot; + &quot;To: &quot; + strTo + &quot;\n&quot; + &quot;Subject: &quot; + strSubject + &quot;\n&quot; + &quot;Date: &quot; + Convert.ToDateTime(&quot;9/11/2001 11:45 AM&quot;) + &quot;\n&quot; + &quot;X-Mailer: My DAV mailer&quot; + &quot;\n&quot; + &quot;MIME-Version: 1.0&quot; + &quot;\n&quot; + &quot;Content-Type: text/plain;&quot; + &quot;\n&quot; + &quot;Charset = \&quot;iso-8859-1\&quot;&quot; + &quot;\n&quot; + &quot;Content-Transfer-Encoding: 7bit&quot; + &quot;\n&quot; + &quot;\n&quot; + 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);

Console.WriteLine(sQuery); oXMLHttp.send(sQuery);

Console.WriteLine(oXMLHttp.status); Console.WriteLine(oXMLHttp.statusText); Console.WriteLine(oXMLHttp.responseText); }           catch (Exception e)            { Console.WriteLine(&quot;{0} Exception caught.&quot;, e); }

}

private String FindSubmissionURL(String strExchSvr,            String strAlias,             String strUserName,             String strPassWord) {           String query; String strURL; String baseName = &quot;&quot;; MSXML2.XMLHTTP30 xmlReq = new MSXML2.XMLHTTP30;

MSXML2.DOMDocument xmldom = new MSXML2.DOMDocument; MSXML2.IXMLDOMElement xmlRoot; MSXML2.IXMLDOMNode xmlNode; //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 && xmlReq.status < 300) {                  xmldom.loadXML(xmlReq.responseText);   // working! xmlRoot = xmldom.documentElement;

for(int i = 1; i <= xmlRoot.attributes.length; i++) {                   xmlNode  = xmlRoot.attributes[i]; if(xmlNode.text == &quot;urn:schemas:httpmail:&quot;) {                       baseName = xmlNode.baseName; break; }               }

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

}           else {               Console.WriteLine(&quot;Failed to find mail submission URL&quot;); return &quot;&quot;; }

xmlReq = null; xmldom = null; xmlRoot = null; xmlNode = null;

return &quot;&quot;;

}

} }                   </li> Search for the TODO text string in the code, and then modify the code for your environment.</li> Press F5 to build and to run the program.</li> Make sure that the e-mail message was sent and was received.</li></ol>

Additional query words: send mail SubmissionURL WebDAV

Keywords: kbxml kbcode kbmsg kbhowtomaster KB310292

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.