http://www.dotnetjunkies.com/Tutorial/ShowContent.aspx?cg=2E1EEEAF-C78A-4A38-A830-AC204B12DF83&forumID=4094这里有比较详细的说明,并有源代码。主要是因为OutLook的版本不同,对象也有所不同,我看你的代码好像是已经是XP以上的版本了,而一般的代码都是针对Outlook 2000来的。不过没有关系,在上面的源代码中,你的VS.Net可能不识别你的Outlook版本,但是别人已经帮你编译好了:))呵呵,你再引用一次bin目录中的msoutl9.dll就可以了。注意outlook2000的版本是9,xp是10,2003是11。我在我的outlook 2003(XP)中测试了下面的程序,没有错误,如下:(你需要的代码)using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using msoutl9;namespace OutLook
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //
// TODO: Add any constructor code after InitializeComponent call
//
} /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null) 
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
// 
// button1
// 
this.button1.Location = new System.Drawing.Point(160, 112);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
// 
// Form1
// 
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() 
{
System.Windows.Forms.Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{
msoutl9.Application objOutlook = new msoutl9.ApplicationClass();
msoutl9.NameSpace objNS = objOutlook.GetNamespace("MAPI");
//获取收件箱
msoutl9.MAPIFolder objFolder = objNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox); int iMailCount = objFolder.Items.Count;
int iNewMailCount = 0; for(int i=0;i<iMailCount;i++)
{
msoutl9.MailItem myItem = (MailItem)objFolder.Items.GetNext();
if(myItem.UnRead)
iNewMailCount++;
} objOutlook.Quit(); MessageBox.Show("OutLook 中共有邮件:" + iMailCount.ToString() + "封\n 其中新邮件:" + iNewMailCount.ToString());
}
}
}