473,946 Members | 12,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Rrecipient List

Does anyone have an example of C# code on how to get Email Rrecipients
List from Active Directory?
Nov 16 '05 #1
4 3475
Hi Peter,

I did not figure what do you mean very well.
Do you mean you wants to get the items in the Contact Folder in the Outlook
or the recipient of a MailMessage?
Here is some code that will automation outlook to Enumerate the Contact Box
or Enumerate the recipients in a sentmail.

using System;
using Outlook = Microsoft.Offic e.Interop.Outlo ok;
namespace AutoOutLook
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
//Enumerate the Contact Box
Outlook.Applica tion olApp = new Outlook.Applica tionClass();
Outlook.MAPIFol der mf =
olApp.GetNamesp ace("MAPI").Get DefaultFolder(O utlook.OlDefaul tFolders.olFold e
rContacts);
foreach(object ci in mf.Items)
{
if (ci as Outlook.Contact Item != null)
Console.WriteLi ne(((Outlook.Co ntactItem)ci).F ullName);
}
//Enumerate the recipients in a sentmail
Outlook.MAPIFol der mf2 =
olApp.GetNamesp ace("MAPI").Get DefaultFolder(O utlook.OlDefaul tFolders.olFold e
rSentMail);
Console.WriteLi ne(mf2.Items.Co unt);
Outlook.MailIte m mi = (Outlook.MailIt em)mf2.Items.Ge tFirst();
foreach (object recip in mi.Recipients)
{
if (recip as Outlook.Recipie nt != null)
Console.WriteLi ne(((Outlook.Re cipient)recip). Name);
}
}
}
}

If I misunderstandin g you meaning, can you describe what do you mean more
detailed and what do you want to do detailed?
I will appreciate your efforts.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 16 '05 #2
That's not what I meant, but actually this might work better for me.

Thank you very much!
I am getting the following error in the example:

foreach statement cannot operate on variables of type 'Outlook.Items'
because 'Outlook.Items' does not contain a definition for 'GetEnumerator' ,
or it is inaccessible

I am using Office XP.

How can iterate through all of the Items either using foreach or for loop?

""Peter Huang"" <v-******@online.m icrosoft.com> wrote in message
news:bI******** ******@cpmsftng xa10.phx.gbl...
Hi Peter,

I did not figure what do you mean very well.
Do you mean you wants to get the items in the Contact Folder in the Outlook or the recipient of a MailMessage?
Here is some code that will automation outlook to Enumerate the Contact Box or Enumerate the recipients in a sentmail.

using System;
using Outlook = Microsoft.Offic e.Interop.Outlo ok;
namespace AutoOutLook
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
//Enumerate the Contact Box
Outlook.Applica tion olApp = new Outlook.Applica tionClass();
Outlook.MAPIFol der mf =
olApp.GetNamesp ace("MAPI").Get DefaultFolder(O utlook.OlDefaul tFolders.olFold e rContacts);
foreach(object ci in mf.Items)
{
if (ci as Outlook.Contact Item != null)
Console.WriteLi ne(((Outlook.Co ntactItem)ci).F ullName);
}
//Enumerate the recipients in a sentmail
Outlook.MAPIFol der mf2 =
olApp.GetNamesp ace("MAPI").Get DefaultFolder(O utlook.OlDefaul tFolders.olFold e rSentMail);
Console.WriteLi ne(mf2.Items.Co unt);
Outlook.MailIte m mi = (Outlook.MailIt em)mf2.Items.Ge tFirst();
foreach (object recip in mi.Recipients)
{
if (recip as Outlook.Recipie nt != null)
Console.WriteLi ne(((Outlook.Re cipient)recip). Name);
}
}
}
}

If I misunderstandin g you meaning, can you describe what do you mean more
detailed and what do you want to do detailed?
I will appreciate your efforts.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 16 '05 #3
Hi Peter,

The Object Modal of outlook catalogized the items as a few MAPI folders,
e.g. Contacts, Send Mail and so on.
So if we wants to iterate all the item in the outlook we may need to get
the folder first.
e.g.
Outlook.MAPIFol der mf =
olApp.GetNamesp ace("MAPI").Get DefaultFolder(O utlook.OlDefaul tFolders.olFold e
rContacts);
The code line above will retrieve the Contact folder and then we can
iterate the items in the folder.

The code I post will runs fine on my side.
Have you tried the exact code I post in my last post?
Which code line gives out the error message?

To isolate the problem, you may try to add a reference to the outlook and
then copy and paste the code below into an console application for a test.

using System;
using Outlook = Microsoft.Offic e.Interop.Outlo ok;
namespace AutoOutLook
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Outlook.Applica tion olApp = new Outlook.Applica tionClass();
Outlook.MAPIFol der mailFolder =
olApp.GetNamesp ace("MAPI").Get DefaultFolder(O utlook.OlDefaul tFolders.olFold e
rInbox);
Outlook.MailIte m mItem = (Outlook.MailIt em)mailFolder.I tems[1];
Console.WriteLi ne(mItem.Subjec t);
foreach( object mi in mailFolder.Item s)
{
if ( mi as Outlook.MailIte m !=null)
Console.WriteLi ne(((Outlook.Ma ilItem)mi).Subj ect);
}

}
}
}

You may have a try and let me know the result.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 16 '05 #4
I found the problem with the code, Office 10 does not implement a
GetEnumerator() method that's why it does not work on my computer.

But I am back to the original problem, is there a way to get email address
list from GAL using Active Directory or some other method without Outlook or
any other COM programs? Because Outlook displays the dialog box when you
try to access an email address, and that gets annoying realy fast. I am
converting an Outlook Form to C# program, because of the problems with the
new security features and I need to display the Global Address List for the
user.

Peter

Thanks

""Peter Huang"" <v-******@online.m icrosoft.com> wrote in message
news:2E******** ******@cpmsftng xa10.phx.gbl...
Hi Peter,

The Object Modal of outlook catalogized the items as a few MAPI folders,
e.g. Contacts, Send Mail and so on.
So if we wants to iterate all the item in the outlook we may need to get
the folder first.
e.g.
Outlook.MAPIFol der mf =
olApp.GetNamesp ace("MAPI").Get DefaultFolder(O utlook.OlDefaul tFolders.olFold e rContacts);
The code line above will retrieve the Contact folder and then we can
iterate the items in the folder.

The code I post will runs fine on my side.
Have you tried the exact code I post in my last post?
Which code line gives out the error message?

To isolate the problem, you may try to add a reference to the outlook and
then copy and paste the code below into an console application for a test.

using System;
using Outlook = Microsoft.Offic e.Interop.Outlo ok;
namespace AutoOutLook
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Outlook.Applica tion olApp = new Outlook.Applica tionClass();
Outlook.MAPIFol der mailFolder =
olApp.GetNamesp ace("MAPI").Get DefaultFolder(O utlook.OlDefaul tFolders.olFold e rInbox);
Outlook.MailIte m mItem = (Outlook.MailIt em)mailFolder.I tems[1];
Console.WriteLi ne(mItem.Subjec t);
foreach( object mi in mailFolder.Item s)
{
if ( mi as Outlook.MailIte m !=null)
Console.WriteLi ne(((Outlook.Ma ilItem)mi).Subj ect);
}

}
}
}

You may have a try and let me know the result.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3118
by: massimo | last post by:
Hey, I wrote this program which should take the numbers entered and sort them out. It doesnąt matter what order, if decreasing or increasing. I guess I'm confused in the sorting part. Anyone has any advices?? #include <iostream> using namespace std;
10
15165
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy *enemydata; // Holds information about an enemy (in a game) // Its a double linked list node
24
5827
by: Robin Cole | last post by:
I'd like a code review if anyone has the time. The code implements a basic skip list library for generic use. I use the following header for debug macros: /* public.h - Public declarations and macros */ #ifndef PUBLIC #define PUBLIC
4
3618
by: JS | last post by:
I have a file called test.c. There I create a pointer to a pcb struct: struct pcb {   void *(*start_routine) (void *);   void *arg;   jmp_buf state;   int    stack; };   struct pcb *pcb_pointer;
3
2719
by: chellappa | last post by:
hi this simple sorting , but it not running...please correect error for sorting using pointer or linked list sorting , i did value sorting in linkedlist please correct error #include<stdio.h> #include<stdlib.h> int main(void) {
0
1832
by: drewy2k12 | last post by:
Heres the story, I have to create a doubly linked list for class, and i have no clue on how to do it, i can barely create a single linked list. It has to have both a head and a tail pointer, and each node in the list must contain two pointers, one pointing forward and one pointing backwards. Each node in the list will contain 3 data values: an item ID (string), a quantity (integer) and a price (float). The ID will contain only letters and...
10
6612
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
0
8652
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be anything from a short integer value to a complex struct type, also has a pointer to the next node in the single-linked list. That pointer will be NULL if the end of the single-linked list is encountered. The single-linked list travels only one...
12
4080
by: kalyan | last post by:
Hi, I am using Linux + SysV Shared memory (sorry, but my question is all about offset + pointers and not about linux/IPC) and hence use offset's instead on pointers to store the linked list in the shared memory. I run fedora 9 and gcc 4.2. I am able to insert values in to the list, remove values from the list, but the problem is in traversing the list. Atlease one or 2 list nodes disappear when traversing from the base of the list or...
0
10162
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11153
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10688
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7427
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6112
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6331
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4533
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3541
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.