using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LumiSoft.Net;
using LumiSoft.Net.Log;
using LumiSoft.Net.Mime;
using LumiSoft.Net.MIME;
using LumiSoft.Net.Mail;
using LumiSoft.Net.POP3.Client;
namespace hjt
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//m_pTabMail_Messages = new ListView();
//m_pTabMail_Messages.Size = new Size(690, 200);
//m_pTabMail_Messages.Location = new Point(5, 30);
//m_pTabMail_Messages.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
m_pTabMail_Messages.View = View.Details;
m_pTabMail_Messages.HideSelection = false;
m_pTabMail_Messages.FullRowSelect = true;
m_pTabMail_Messages.Columns.Add("From", 100);
m_pTabMail_Messages.Columns.Add("Subject", 300);
m_pTabMail_Messages.Columns.Add("Received", 120);
m_pTabMail_Messages.Columns.Add("Size", 60);
m_pTabMail_Attachments.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
m_pTabMail_Attachments.View = View.SmallIcon;
GetEmails();
}
public void GetEmails()
{
//需要首先设置这些信息
string pop3Server;
int pop3Port;
bool pop3UseSsl;
string username;
List gotEmailIds;
List result = new List();
POP3_Client pop3 = new POP3_Client();
pop3Server = "pop3.sany.com.cn";
pop3Port = 110;
pop3UseSsl = false;
username = "huangjt";
string password = "wstj123!";
//与Pop3服务器建立连接
pop3.Connect(pop3Server, pop3Port, pop3UseSsl);
//验证身份
//pop3.Authenticate(username, password, false);
pop3.Login(username, password);
//获取邮件信息列表
POP3_ClientMessageCollection infos = pop3.Messages;
foreach (POP3_ClientMessage message in infos)
{
Mail_Message mime = Mail_Message.ParseFromByte(message.HeaderToByte());
ListViewItem item = new ListViewItem();
if (mime.From != null)
{
item.Text = mime.From.ToString();
}
else
{
item.Text = "";
}
if (string.IsNullOrEmpty(mime.Subject))
{
item.SubItems.Add("");
}
else
{
item.SubItems.Add(mime.Subject);
}
item.SubItems.Add(mime.Date.ToString());
item.SubItems.Add(((decimal)(message.Size / (decimal)1000)).ToString("f2") + " kb");
item.Tag = message;
m_pTabMail_Messages.Items.Add(item);
}
}
private void m_pTabMail_Messages_SelectedIndexChanged(object sender, EventArgs e)
{
if (m_pTabMail_Messages.SelectedItems.Count > 0)
{
m_pTabMail_Attachments.Items.Clear();
m_pTabMail_BodyText.Text = "";
POP3_ClientMessage message = (POP3_ClientMessage)m_pTabMail_Messages.SelectedItems[0].Tag;
Mail_Message mime = Mail_Message.ParseFromByte(message.MessageToByte());
foreach (MIME_Entity entity in mime.Attachments)
{
ListViewItem item = new ListViewItem();
if (entity.ContentDisposition != null && entity.ContentDisposition.Param_FileName != null)
{
item.Text = entity.ContentDisposition.Param_FileName;
}
else
{
item.Text = "untitled";
}
item.Tag = entity;
m_pTabMail_Attachments.Items.Add(item);
}
if (mime.BodyText != null)
{
m_pTabMail_BodyText.Text = mime.BodyText;
}
}
}
}
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/11238514/viewspace-764129/,如需转载,请注明出处,否则将追究法律责任。