DNS namespace and System. A successful name resolution will result in an IPAddress object. We convert the IPAddress to a string and write out a friendly message saying we have contacted the mail server. Any errors are trapped in a socket exception, where we write out an error message and stop processing the rest of the page. In listing 1.2a we create use the System.
Sockets namespace to create two objects, a networkstream and a TCPClient.
These will be explained in code listing 1.2b. In listing 1.2b, we demonstrate the different worker functions we use to move data to and from the mail server. Once we have the byte array, we write the array to the networkstream. Once we have the array, we check the length of the networkstream. Now that we have successfully opened a connection to the mail server, we can send and receive standard RFC821 commands.