日期:2010-04-27 浏览次数:20509 次
*
w3 JMail v4.4 Professional 的获取请自行 google!
或参阅 http://community.csdn.net/Expert/TopicView.asp?id=3739405
w3 JMail v4.4 Professional 是一个 COM 的组件,我用 C# 把其 POP3 COM 类封装成
一个用于收取邮件的 .Net 组件:
实现了
//同步事件
public event MessagesEventHandler MessageReceived; //一封邮件已收到本地
public event MessagesEventHandler MessageReceive; //一封邮件正到达
//可用于收取邮件的每个附件处理
public event AttachmentsEventHandler AttachmentReceive; //一封邮件的附件正到达
//发生异常事件
public event MessagesEventHandler MessageException;
public event AttachmentsEventHandler AttachmentException;
因此在调用该组件的主调程序中可根据分析邮件的主题或附件等结果作不同处理!
将如下所有代码:
1.复制到 Microsoft Visual Studio .Net 2003 的新建的 "控制台应用程序" 项目的 *.cs 文件中
2.然后添加引用 JMail 4.x Library!
jmail 的注册方法,运行命令行: regsvr32 e:\jmail\jmail.dll
3.F5 运行
或者
将如下所有代码:
1.复制到任意一个 *.cs 文件中保存!(如: e:\temp\NJMail.cs)
2.使用 tlbimp.exe(类型库导入程序)实用工具生成一个 .Net 程序集
执行命令行: (位于 Ms VS.Net 安装目录下的: E:\MsVS.Net\SDK\v1.1\Bin\TlbImp.exe)
tlbimp.exe e:\jmail\jmail.dll /out:e:\temp\jmail.net.dll /namespace:jmail
生成的 jmail.net.dll 与 *.cs 文件放在同一目录下!
3.执行 csc 命令行编译 *.cs
编译成 exe : (这里是为了演示测试效果所以编译成 exe)
csc.exe NJMail.cs /r:jmail.net.dll
编译成 dll ,即可由别的 .Net 程序添加引用:
csc.exe /t:library NJMail.cs /r:jmail.net.dll
(当然也可将 namespace Microshaoft.NJMail 下的代码单独编译成 dll)
*/
namespace Microshaoft.NJMail
{
//using jmail;
//using System;
public class POP3
{
public delegate void MessagesEventHandler(MessagesState oMessagesState);
public delegate void AttachmentsEventHandler(AttachmentsState oAttachmentsState);
//异步事件
public event MessagesEventHandler MessagesReceiveAsync;
public event AttachmentsEventHandler AttachmentsReceiveAsync;
//同步事件
public event MessagesEventHandler MessageReceived;
public event MessagesEventHandler MessageReceive;
public event AttachmentsEventHandler AttachmentReceive;
//发生异常事件
public event MessagesEventHandler MessageException;
public event AttachmentsEventHandler AttachmentException;
private string _UserName;
private string _Password;
private string _Server;
private int _Port = 110;
private static object _LockObject = new object();
public POP3(string UserName,string Password,string Server,int Port)
{
this._UserName = UserName;
this._Password = Password;
this._Server = Server;
this._Port = Port;
}
public POP3(string UserName,string Password,string Server)
{
this._UserName = UserName;
this._Password = Password;
this._Server = Server;
}
//[MTAThread]
public void Execute()
{
this.Execute(false);
}
public void Execute(bool IsAsync)
{
jmail.POP3Class pop3 = new jmail.POP3Class();
try
{
pop3.Timeout = 0;
pop3.Connect(this._UserName,this._Password,this._Server,this._Port);
jmail.MessagesClass jms = (jmail.MessagesClass) pop3.Messages;
int I = jms.Count;
MessagesState omss = nul