111,097
社区成员




private void button3_Click(object sender, EventArgs e)
{
try
{
ns = ac.GetNamespace("MAPI");
//使用对应账号,密码登陆相应邮箱
//ns.Logon("", "", false, true);
}
catch (System.Exception error)
{
throw new System.Exception("登陆Outlook失败" + error.Message);
}
MAPIFolder inbox = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
//邮箱中的所有数目
int count = inbox.Items.Count;
//收件人
string Receiver = ""; //当前收件人
Recipients recipients; //全部收件人集合
//收件人数目
int intReceiverCount;
foreach (Object obj in inbox.Items)
{
MailItem item = obj as MailItem;
Receiver = item.ReceivedByName;
//收件人群体集合
recipients = item.Recipients;
//收件人数目
intReceiverCount = recipients.Count;
foreach (Recipient receipient in recipients)
{
//ReceiverAll = ReceiverAll + receipient.Name + ";";
listBox1.Items.Add(receipient.Name);
}
}
}
using System;
using OutlookInterop = Microsoft.Office.Interop.Outlook;
namespace OutlookContact
{
class Program
{
public static void Main(string[] args)
{
GetContact();
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
public static void GetContact()
{
// create new instance of the Outlook app
OutlookInterop.ApplicationClass app = new OutlookInterop.ApplicationClass();
// get path to the MAPI api
OutlookInterop.NameSpace ns = app.GetNamespace("MAPI");
// get path to the contacts folder. Use the OlDefaultFolders enum to specify
// that we want to get the olFolderContacts folder.
OutlookInterop.MAPIFolder contactsFolder = app.ActiveExplorer().Session.GetDefaultFolder(
OutlookInterop.OlDefaultFolders.olFolderContacts);
// Get list of all contacts in Outlook.
OutlookInterop.Items contactItems = contactsFolder.Items;
// loop the list of contacts returned
foreach (OutlookInterop.ContactItem Item in contactItems)
{
// do something with each contact
string sFirstName = Item.FirstName;
string sLastname = Item.LastName;
string sEmail = Item.Email1Address;
Console.WriteLine(string.Format("{0} {1} {2}", sFirstName, sLastname, sEmail));
}
}
}
}
OutlookInterop.MAPIFolder contactsFolder = app.ActiveExplorer().Session.GetDefaultFolder(
OutlookInterop.OlDefaultFolders.olFolderContacts);