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

    <form id="Form1" method="post" runat="server">
	<h3>This example uses aspNetPOP3 and aspNetMime to read the first message from a POP3 server and display it on this page.</h3>
			<td><asp:Literal ID=litFrom Runat=server></asp:Literal></td>
			<td><asp:Literal ID=litTo Runat=server></asp:Literal></td>
			<td><asp:Literal ID=litSubject Runat=server></asp:Literal></td>
			<td colspan=2>
				<pre><asp:Literal ID=litContents Runat=server></asp:Literal></pre>
				Attachment List
				<asp:Literal ID=litAttachments Runat=server></asp:Literal>





Imports aspNetMime
Imports aspNetPOP3

Public Class getmessage
    Inherits System.Web.UI.Page
    Protected WithEvents litFrom As System.Web.UI.WebControls.Literal
    Protected WithEvents litTo As System.Web.UI.WebControls.Literal
    Protected WithEvents litSubject As System.Web.UI.WebControls.Literal
    Protected WithEvents litContents As System.Web.UI.WebControls.Literal
    Protected WithEvents litAttachments As System.Web.UI.WebControls.Literal

#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

        'create the POP3 object
        Dim pop As POP3 = New POP3("", "", "mypassword")

        'connect to the server

        'get the message
        Dim m As MimeMessage = pop.GetMessage(0)


        'display the message contents 
        If Not m.To Is Nothing Then
            litTo.Text = Server.HtmlEncode(m.To.ToString())
        End If

        If Not m.From Is Nothing Then
            litFrom.Text = Server.HtmlEncode(m.From.ToString())
        End If

        If Not m.Subject Is Nothing Then
            litSubject.Text = Server.HtmlEncode(m.Subject.Value)
            litSubject.Text = "(no subect)"
        End If

        If Not m.MainBody Is Nothing Then
            litContents.Text = m.MainBody
        End If

        'check for attachments
        Dim attachments As MimePartCollection = m.Attachments
        If attachments.Count > 0 Then
            'if there are attachments, then write out their names
            Dim attachment As MimePart
            For Each attachment In attachments
                litAttachments.Text += attachment.AttachmentName() + "<BR>"
            litAttachments.Text = "(no attachments)"
        End If
    End Sub

End Class