getmessage.aspx
<%@ Page language="c#" Codebehind="getmessage.aspx.cs" AutoEventWireup="false" Inherits="aspNetMimeTest.getmessage" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>getmessage</title>
</HEAD>
<body >
<form id="getmessage" 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>
getmessage.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using aspNetMime;
using aspNetPOP3;
namespace aspNetMimeTest
{
/// <summary>
/// Summary description for getmessage.
/// </summary>
public class getmessage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Literal litFrom;
protected System.Web.UI.WebControls.Literal litTo;
protected System.Web.UI.WebControls.Literal litSubject;
protected System.Web.UI.WebControls.Literal litContents;
protected System.Web.UI.WebControls.Literal litAttachments;
private void Page_Load(object sender, System.EventArgs e)
{
//create the POP3 object
POP3 pop = new POP3( "127.0.0.1", "dave@blah.com", "mypassword" );
//connect to the server
pop.Connect();
//get the message
MimeMessage m = pop.GetMessage(0);
//disconnect
pop.Disconnect();
//display the message contents
if( m.To != null )
litTo.Text = Server.HtmlEncode( m.To.ToString() );
if( m.From != null )
litFrom.Text = Server.HtmlEncode( m.From.ToString() );
if( m.Subject != null )
litSubject.Text = Server.HtmlEncode( m.Subject.Value );
else
litSubject.Text = "(no subect)";
if( m.MainBody != null )
litContents.Text = m.MainBody;
//check for attachments
MimePartCollection attachments = m.Attachments;
if( attachments.Count > 0 )
{
//if there are attachments, then write out their names
foreach(MimePart attachment in attachments )
{
litAttachments.Text += attachment.AttachmentName() + "<BR>";
}
}
else
{
litAttachments.Text = "(no attachments)";
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}