<%@ Page Language="vb" AutoEventWireup="false" Codebehind="getmessage.aspx.vb" Inherits="aspNetPopTestvb.getmessage"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  <body >

    <form id="Form1" method="post" runat="server">
				<td>Enter your Server Address</td>
				<td><input type=text id="txtServer" runat=server NAME="txtServer"><asp:RequiredFieldValidator id=RequiredFieldValidator1 runat="server" ErrorMessage="Required" ControlToValidate="txtServer"></asp:RequiredFieldValidator> </td>
				<td>Enter your username</td>
				<td><input type=text id=txtUsername runat=server NAME="txtUsername"><asp:RequiredFieldValidator id=RequiredFieldValidator2 runat="server" ErrorMessage="Required" ControlToValidate="txtUsername"></asp:RequiredFieldValidator></td>
				<td>Enter your password</td>
				<td><input type=password id=txtPassword runat=server NAME="txtPassword"><asp:RequiredFieldValidator id=RequiredFieldValidator3 runat="server" ErrorMessage="Required" ControlToValidate="txtPassword"></asp:RequiredFieldValidator></td>
				<td colspan=2 align=middle><input type=submit id=cmdSubmit value="Download 1st Message" runat=server NAME="cmdSubmit"></td>
		<asp:literal ID=Message1 Runat=server></asp:literal>




Imports aspNetPOP3

Public Class getmessage
    Inherits System.Web.UI.Page
    Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator3 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents Message1 As System.Web.UI.WebControls.Literal
    Protected WithEvents txtServer As System.Web.UI.HtmlControls.HtmlInputText
    Protected WithEvents txtUsername As System.Web.UI.HtmlControls.HtmlInputText
    Protected WithEvents txtPassword As System.Web.UI.HtmlControls.HtmlInputText
    Protected WithEvents cmdSubmit As System.Web.UI.HtmlControls.HtmlInputButton

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
    End Sub

    Private Sub cmdSubmit_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.ServerClick
        'normally validate username and password. Validation left out for code simplification
        Dim pop As New POP3(txtServer.Value, txtUsername.Value, txtPassword.Value)

            'connect to the server
        Catch ex As Exception
            'record an exceptions and exit
            Message1.Text = "<font color=red>The following exception occurred: <br>" + ex.Message + "</font>"
        End Try

        Dim count As Integer = pop.MessageCount()
        Dim msg As String = String.Empty
        If count > 1 Then
            'get the first message
            msg = "<strong>Message 1</strong><br><br>"
            msg += "<pre>" + Server.HtmlEncode(pop.GetMessageAsText(1)) + "</pre>"
            'if the first message doesn't exist, write out a friendly message
            msg = "No messages at the server"
        End If


        'show the message
        Message1.Text = msg

    End Sub
End Class