home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / tlcTest.aspx.vb < prev    next >
Text File  |  2014-11-01  |  6KB  |  149 lines

  1. ∩╗┐Imports AspNetMaker7_tfpssnet
  2.  
  3. Partial Class tlcTest
  4.     Inherits System.Web.UI.Page
  5.  
  6.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  7.  
  8.         ' Variables.
  9.         Dim PUTRequest As System.Net.HttpWebRequest
  10.         Dim PUTResponse As System.Net.HttpWebResponse
  11.         Dim MOVERequest As System.Net.HttpWebRequest
  12.         Dim MOVEResponse As System.Net.HttpWebResponse
  13.         Dim MyCredentialCache As System.Net.CredentialCache
  14.         Dim strMailboxURI As String
  15.         Dim strSubURI As String
  16.         Dim strTempURI As String
  17.         Dim strServer As String
  18.         Dim strPassword As String
  19.         Dim strDomain As String
  20.         Dim strAlias As String
  21.         Dim strTo As String
  22.         Dim strSubject As String
  23.         Dim strText As String
  24.         Dim strBody As String
  25.         Dim PUTRequestStream As System.IO.Stream
  26.         Dim bytes() As Byte
  27.  
  28.         Try
  29.             ' Initialize variables.
  30.             strServer = "server6"
  31.             strPassword = "production88"
  32.             strDomain = "BUSINESS"
  33.             strAlias = "productionservices"
  34.             strTo = "tonyclayton@tfc.org"
  35.             strSubject = "WebDAV message test."
  36.             strText = "This message was sent using WebDAV."
  37.  
  38.             ' Build the mailbox URI.
  39.             strMailboxURI = "http://" & strServer & "/exchange/" & strAlias
  40.  
  41.             ' Build the submission URI for the message.  If Secure
  42.             ' Sockets Layer (SSL) is set up on the server, use
  43.             ' "https://" instead of "http://".
  44.             strSubURI = "http://" & strServer & "/exchange/" & strAlias _
  45.                & "/##DavMailSubmissionURI##/"
  46.  
  47.             ' Build the temporary URI for the message. If SSL is set
  48.             ' up on the server, use "https://" instead of "http://".
  49.             strTempURI = "http://" & strServer & "/exchange/" & strAlias & _
  50.                "/drafts/" & strSubject & ".eml"
  51.  
  52.             ' Construct the RFC 822 formatted body of the PUT request.
  53.             ' Note: If the From: header is included here,
  54.             ' the MOVE method request will return a
  55.             ' 403 (Forbidden) status. The From address will
  56.             ' be generated by the Exchange server.
  57.             strBody = "To: " & strTo & vbNewLine & _
  58.                "Subject: " & strSubject & vbNewLine & _
  59.                "Date: " & System.DateTime.Now & _
  60.                "X-Mailer: test mailer" & vbNewLine & _
  61.                "MIME-Version: 1.0" & vbNewLine & _
  62.                "Content-Type: text/plain;" & vbNewLine & _
  63.                "Charset = ""iso-8859-1""" & vbNewLine & _
  64.                "Content-Transfer-Encoding: 7bit" & vbNewLine & _
  65.                vbNewLine & strText
  66.  
  67.             ' Create a new CredentialCache object and fill it with the network
  68.             ' credentials required to access the server.
  69.             MyCredentialCache = New System.Net.CredentialCache
  70.             MyCredentialCache.Add(New System.Uri(strMailboxURI), _
  71.                "NTLM", _
  72.                New System.Net.NetworkCredential(strAlias, strPassword, strDomain) _
  73.                )
  74.  
  75.             ' Create the PUT HttpWebRequest object.
  76.             PUTRequest = CType(System.Net.WebRequest.Create(strTempURI),  _
  77.                System.Net.HttpWebRequest)
  78.  
  79.             ' Add the network credentials to the request.
  80.             PUTRequest.Credentials = MyCredentialCache
  81.  
  82.             ' Specify the PUT method.
  83.             PUTRequest.Method = "PUT"
  84.  
  85.             ' Encode the body using UTF-8.
  86.             bytes = System.Text.Encoding.UTF8.GetBytes(strBody)
  87.  
  88.             ' Set the content header length.  This must be
  89.             ' done before writing data to the request stream.
  90.             PUTRequest.ContentLength = bytes.Length
  91.  
  92.             ' Get a reference to the request stream.
  93.             PUTRequestStream = PUTRequest.GetRequestStream()
  94.  
  95.             ' Write the message body to the request stream.
  96.             PUTRequestStream.Write(bytes, 0, bytes.Length)
  97.  
  98.             ' Close the Stream object to release the connection
  99.             ' for further use.
  100.             PUTRequestStream.Close()
  101.  
  102.             ' Set the Content-Type header to the RFC 822 message format.
  103.             PUTRequest.ContentType = "message/rfc822"
  104.  
  105.             ' PUT the message in the Drafts folder of the
  106.             ' sender's mailbox.
  107.             PUTResponse = CType(PUTRequest.GetResponse(), System.Net.HttpWebResponse)
  108.  
  109.             Console.WriteLine("Message successfully PUT to " & strTempURI)
  110.             Label1.Text = "Message successfully PUT to " & strTempURI & vbCrLf
  111.  
  112.             ' Create the MOVE HttpWebRequest object.
  113.             MOVERequest = CType(System.Net.WebRequest.Create(strTempURI),  _
  114.                System.Net.HttpWebRequest)
  115.  
  116.             ' Add the network credentials to the request.
  117.             MOVERequest.Credentials = MyCredentialCache
  118.  
  119.             ' Specify the MOVE method.
  120.             MOVERequest.Method = "MOVE"
  121.  
  122.             ' Set the Destination header to the
  123.             ' mail submission URI.
  124.             MOVERequest.Headers.Add("Destination", strSubURI)
  125.  
  126.             ' Send the message by moving it from the Drafts folder of the
  127.             ' sender's mailbox to the mail submission URI.
  128.             MOVEResponse = CType(MOVERequest.GetResponse(), System.Net.HttpWebResponse)
  129.  
  130.             Console.WriteLine("Message successfully sent to " & strTo)
  131.             Label1.Text = Label1.Text & "Message successfully sent to " & strTo & vbCrLf
  132.  
  133.             ' Clean up.
  134.             PUTResponse.Close()
  135.             MOVEResponse.Close()
  136.  
  137.         Catch ex As Exception
  138.  
  139.             ' Catch any exceptions. Any error codes from the PUT
  140.             ' or MOVE method requests on the server will be caught
  141.             ' here, also.
  142.             Console.WriteLine(ex.Message)
  143.  
  144.         End Try
  145.  
  146.     End Sub
  147.  
  148. End Class
  149.