<%@ Page Language="vb" AutoEventWireup="false" Codebehind="getmessage.aspx.vb" Inherits="aspNetMimeTestvb.getmessage"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>getmessage</title> </HEAD> <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> <table> <tr> <td>From</td> <td><asp:Literal ID=litFrom Runat=server></asp:Literal></td> </tr> <tr> <td>To</td> <td><asp:Literal ID=litTo Runat=server></asp:Literal></td> </tr> <tr> <td>Subject</td> <td><asp:Literal ID=litSubject Runat=server></asp:Literal></td> </tr> <tr> <td colspan=2> <pre><asp:Literal ID=litContents Runat=server></asp:Literal></pre> </td> </tr> <tr> <td> Attachment List </td> <td> <asp:Literal ID=litAttachments Runat=server></asp:Literal> </td> </tr> </table> </form> </body> </HTML>
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. InitializeComponent() 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("127.0.0.1", "dave@blah.com", "mypassword") 'connect to the server pop.Connect() 'get the message Dim m As MimeMessage = pop.GetMessage(0) 'disconnect pop.Disconnect() '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) Else 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>" Next Else litAttachments.Text = "(no attachments)" End If End Sub End Class