Help with some issues in Outlook Plugin development

  • Thread starter Thread starter YW5pbmRhc2VuXzA2MDk
  • Start date Start date
Status
Not open for further replies.
Y

YW5pbmRhc2VuXzA2MDk

I have developed a outlook plugin project and everything is working ok for me

except for two issues. It would be very helpful for me if anyone could throw

some light on them. They are

1. Cannot retrieve some of the email IDs in the To, CC and BCC fields

from the

Item as Outlook.MailItem object. Instead of the email IDs I am getting

the name of the recipient. Eg. "Tom Cruise" instead of tom@hollywood.com

2. The plugin is not trapping the incoming emails when rules are set for

them to

land directly into some other folder based on their email ID. subject or

other criteria.

Thanking you in advance.

Regards,

Aninda
 
1) If by "email IDs," you mean the email addresses, iterate the Recipients

collection and get each Recipient.Address property value.

2) What event are you using for "trapping the incoming emails"?

Application.NewMailEx is your best choice.

Sue Mosher

"anindasen_0609" <anindasen_0609> wrote in message

news:F7436C01-DC23-4C5D-BEC6-2A16123486E5@microsoft.com...
> I have developed a outlook plugin project and everything is working ok for
> me
> except for two issues. It would be very helpful for me if anyone could
> throw
> some light on them. They are

> 1. Cannot retrieve some of the email IDs in the To, CC and BCC fields
> from the
> Item as Outlook.MailItem object. Instead of the email IDs I am getting
> the name of the recipient. Eg. "Tom Cruise" instead of tom@hollywood.com

> 2. The plugin is not trapping the incoming emails when rules are set for
> them to
> land directly into some other folder based on their email ID. subject or
> other criteria.

> Thanking you in advance.

> Regards,
> Aninda
>
 
Thanks a lot for your reply.

1. There are some emails which are stored in the address book with a name.

When emails are received from those clients, the object is returning the name

as fromemail instead of the email id. I tried iterating through recipients

collection but it did not work.

2. This is my code. I am taking the MAPIFolder ItemAdd event to trap the

incoming emails.

Earlier I tried with Application.NewMail but it did not work when multiple

emails were coming in.

Outlook.MAPIFolder oMapiFolder =

this.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

m_Items = oMapiFolder.Items;

m_Items.ItemAdd += new

Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(m_Items_ItemAdd);

what is the difference between Application.NewMailEx and Application.NewMail ?

Regards.

"Sue Mosher [MVP]" wrote:


> 1) If by "email IDs," you mean the email addresses, iterate the Recipients
> collection and get each Recipient.Address property value.

> 2) What event are you using for "trapping the incoming emails"?
> Application.NewMailEx is your best choice.

> > Sue Mosher
> > >

> "anindasen_0609" <anindasen_0609> wrote in message
> news:F7436C01-DC23-4C5D-BEC6-2A16123486E5@microsoft.com...
> >I have developed a outlook plugin project and everything is working ok for
> >me
> > except for two issues. It would be very helpful for me if anyone could
> > throw
> > some light on them. They are
> > 1. Cannot retrieve some of the email IDs in the To, CC and BCC fields
> > from the
> > Item as Outlook.MailItem object. Instead of the email IDs I am getting
> > the name of the recipient. Eg. "Tom Cruise" instead of tom@hollywood.com
> > 2. The plugin is not trapping the incoming emails when rules are set for
> > them to
> > land directly into some other folder based on their email ID. subject or
> > other criteria.
> > Thanking you in advance.
> > Regards,
> > Aninda
> >


>
 
1) I'm confused now. Your original post talked about To, Cc, and Bcc

recipients, but now you seem to be referring to the sender. Which is it? In

what version of Outlook? What specifically didn't work? Show the relevant

code snippet.

2) NewMail tells you only that one or more new messages have arrived.

NewMailEx gives you the EntryID information needed to retrieve them. You can

read about the Application.NewMailEx event in the Outlook developer

reference and see a VBA code example at

http://www.outlookcode.com/codedetail.aspx?id=1410

Sue Mosher

"anindasen_0609" <anindasen0609> wrote in message

news:DFDCE5B5-68AF-45A3-8B05-43C7B754FBD2@microsoft.com...
> Thanks a lot for your reply.

> 1. There are some emails which are stored in the address book with a name.
> When emails are received from those clients, the object is returning the
> name
> as fromemail instead of the email id. I tried iterating through recipients
> collection but it did not work.

> 2. This is my code. I am taking the MAPIFolder ItemAdd event to trap the
> incoming emails.

> Earlier I tried with Application.NewMail but it did not work when multiple
> emails were coming in.

> Outlook.MAPIFolder oMapiFolder =
> this.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
> m_Items = oMapiFolder.Items;
> m_Items.ItemAdd += new
> Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(m_Items_ItemAdd);

> what is the difference between Application.NewMailEx and
> Application.NewMail ?

> Regards.

> "Sue Mosher [MVP]" wrote:
>
> > 1) If by "email IDs," you mean the email addresses, iterate the
> > Recipients
> > collection and get each Recipient.Address property value.
>

>> 2) What event are you using for "trapping the incoming emails"?
> > Application.NewMailEx is your best choice.
>

>> "anindasen_0609" <anindasen_0609> wrote in
> > message
> > news:F7436C01-DC23-4C5D-BEC6-2A16123486E5@microsoft.com...
> > >I have developed a outlook plugin project and everything is working ok
> > >for
> > >me
> > > except for two issues. It would be very helpful for me if anyone could
> > > throw
> > > some light on them. They are
> >> > 1. Cannot retrieve some of the email IDs in the To, CC and BCC
> > > fields
> > > from the
> > > Item as Outlook.MailItem object. Instead of the email IDs I am getting
> > > the name of the recipient. Eg. "Tom Cruise" instead of
> > > tom@hollywood.com
> >> > 2. The plugin is not trapping the incoming emails when rules are set
> > > for
> > > them to
> > > land directly into some other folder based on their email ID. subject
> > > or
> > > other criteria.
> >> > Thanking you in advance.
> >> > Regards,
> > > Aninda
> > >

>

>
>>
 
Thanks for your reply. I am sorry I could not reply earlier.

1) I think I created a confusion. I actually meant all the email fields

ie., From, To, Cc and Bcc. Wherever there is a name for a particular email

address

in the local address book, I am getting the name instead of the email ID.

My function to get email ID against the name is as below:

private string GetEmailID(ref string recipientName)

{

string recipientEmailID = null;

string myQuery = null;

myQuery = "[FullName] = '" + recipientName + "'";

// Create the Outlook application.

Outlook.Application oApp = new Outlook.Application();

// Get the NameSpace information.

Outlook.NameSpace oNS = oApp.GetNamespace("mapi");

// Get the default Contacts folder.

Outlook.MAPIFolder oContacts =

oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);

// Get the Items collection from the folder.

Outlook.Items oItems = (Outlook.Items)oContacts.Items;

// Get the first contact item in the Items collection.

Outlook.ContactItem oCt =

(Outlook.ContactItem)oItems.Find(myQuery);

if (oCt != null)

{

if (oCt.Email1Address.IndexOf("@") != -1)

recipientEmailID = oCt.Email1Address;

else

recipientEmailID = recipientName;

}

else

{

recipientEmailID = recipientName;

}

oCt = null;

oItems = null;

oContacts = null;

oNS = null;

oApp = null;

return recipientEmailID;

}

and I am calling it only when

if (emailAddress.IndexOf("@") <= 0)

{

emailAddress = GetEmailID(ref emailAddress);

}

2) I will definitely look at the resources that you have kindly shared and try

NewMailEx.

3) There is one more problem which I am solving in a rather inelegant way.

I am getting the sender's Email ID from Outlook in a form like:

/O=DOMAIN/OU=FIRST ADMINISTRATIVE GROUP/CN=RE/ou=abcd

if the email ID is - abcd@domain.com.

We are using Active Directory Service and all that I am doing right now is

taking

out the email name and the domain by string manipulation and getting the

email ID from

the database against that. But I am looking for a more proper solution to

this problem.

Thanks.

Aninda

"Sue Mosher [MVP]" wrote:


> 1) I'm confused now. Your original post talked about To, Cc, and Bcc
> recipients, but now you seem to be referring to the sender. Which is it? In
> what version of Outlook? What specifically didn't work? Show the relevant
> code snippet.

> 2) NewMail tells you only that one or more new messages have arrived.
> NewMailEx gives you the EntryID information needed to retrieve them. You can
> read about the Application.NewMailEx event in the Outlook developer
> reference and see a VBA code example at
> http://www.outlookcode.com/codedetail.aspx?id=1410
> > Sue Mosher
> > >

> "anindasen_0609" <anindasen0609> wrote in message
> news:DFDCE5B5-68AF-45A3-8B05-43C7B754FBD2@microsoft.com...
> > Thanks a lot for your reply.
> > 1. There are some emails which are stored in the address book with a name.
> > When emails are received from those clients, the object is returning the
> > name
> > as fromemail instead of the email id. I tried iterating through recipients
> > collection but it did not work.
> > 2. This is my code. I am taking the MAPIFolder ItemAdd event to trap the
> > incoming emails.
> > Earlier I tried with Application.NewMail but it did not work when multiple
> > emails were coming in.
> > Outlook.MAPIFolder oMapiFolder =
> > this.Application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
> > m_Items = oMapiFolder.Items;
> > m_Items.ItemAdd += new
> > Microsoft.Office.Interop.Outlook.ItemsEvents_ItemAddEventHandler(m_Items_ItemAdd);
> > what is the difference between Application.NewMailEx and
> > Application.NewMail ?
> > Regards.
> > "Sue Mosher [MVP]" wrote:
> >
> >> 1) If by "email IDs," you mean the email addresses, iterate the
> >> Recipients
> >> collection and get each Recipient.Address property value.
> >
> >> 2) What event are you using for "trapping the incoming emails"?
> >> Application.NewMailEx is your best choice.
> >
> >> "anindasen_0609" <anindasen_0609> wrote in
> >> message
> >> news:F7436C01-DC23-4C5D-BEC6-2A16123486E5@microsoft.com...
> >> >I have developed a outlook plugin project and everything is working ok
> >> >for
> >> >me
> >> > except for two issues. It would be very helpful for me if anyone could
> >> > throw
> >> > some light on them. They are
> >> >> > 1. Cannot retrieve some of the email IDs in the To, CC and BCC
> >> > fields
> >> > from the
> >> > Item as Outlook.MailItem object. Instead of the email IDs I am getting
> >> > the name of the recipient. Eg. "Tom Cruise" instead of
> >> > tom@hollywood.com
> >> >> > 2. The plugin is not trapping the incoming emails when rules are set
> >> > for
> >> > them to
> >> > land directly into some other folder based on their email ID. subject
> >> > or
> >> > other criteria.
> >> >> > Thanking you in advance.
> >> >> > Regards,
> >> > Aninda
> >> >
> >
> >>


>
 
Sue's on vacation.

I see a few flaws in your code.

First of all, in an Outlook COM addin, never create a new

Outlook.Application object. Always use the Application object passed to you

in your startup code handler or in OnConnection.

Second, that code will only look at contacts. If a recipient is from the GAL

then you never will find anything.

As Sue recommended it's really best to work with the Recipients collection

and iterate that. You said that didn't work but didn't provide any

information as to why. Each Recipient object has an Address property .

That's what you should be using.

When the Recipient is part of an Exchange domain you won't get back an SMTP

style address, you'll get back an Exchange DN type address such as your

example: /O=DOMAIN/OU=FIRST ADMINISTRATIVE GROUP/CN=RE/ou=abcd.

In those cases you would need to convert the EX address into an SMTP

equivalent. Since you never mention which version or versions of Outlook you

are targeting it's hard to be specific as to how you would convert the

address. Take a look at

http://www.outlookcode.com/threads.aspx?forumid=4&messageid=13469 for some

suggestions as to how to do that. Note that since you're using managed code

(C#) the CDO option is not available to you, CDO is not supported and should

not be used with managed code.

You can also search at www.outlookcode.com using something like "convert

exchange address to smtp" to look at other forum threads on that topic.

"anindasen_0609" <anindasen0609> wrote in message

news:88E397B3-696F-41AE-B964-C6C4243AA2C6@microsoft.com...
> Thanks for your reply. I am sorry I could not reply earlier.

> 1) I think I created a confusion. I actually meant all the email fields
> ie., From, To, Cc and Bcc. Wherever there is a name for a particular email
> address
> in the local address book, I am getting the name instead of the email ID.

> My function to get email ID against the name is as below:

> private string GetEmailID(ref string recipientName)
> {
> string recipientEmailID = null;
> string myQuery = null;
> myQuery = "[FullName] = '" + recipientName + "'";

> // Create the Outlook application.
> Outlook.Application oApp = new Outlook.Application();
> // Get the NameSpace information.
> Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
> // Get the default Contacts folder.
> Outlook.MAPIFolder oContacts =
> oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
> // Get the Items collection from the folder.
> Outlook.Items oItems = (Outlook.Items)oContacts.Items;
> // Get the first contact item in the Items collection.
> Outlook.ContactItem oCt =
> (Outlook.ContactItem)oItems.Find(myQuery);

> if (oCt != null)
> {
> if (oCt.Email1Address.IndexOf("@") != -1)
> recipientEmailID = oCt.Email1Address;
> else
> recipientEmailID = recipientName;
> }
> else
> {
> recipientEmailID = recipientName;
> }

> oCt = null;
> oItems = null;
> oContacts = null;
> oNS = null;
> oApp = null;

> return recipientEmailID;
> }

> and I am calling it only when

> if (emailAddress.IndexOf("@") <= 0)
> {
> emailAddress = GetEmailID(ref emailAddress);
> }

> 2) I will definitely look at the resources that you have kindly shared and
> try
> NewMailEx.

> 3) There is one more problem which I am solving in a rather inelegant way.
> I am getting the sender's Email ID from Outlook in a form like:

> /O=DOMAIN/OU=FIRST ADMINISTRATIVE GROUP/CN=RE/ou=abcd

> if the email ID is - abcd@domain.com.

> We are using Active Directory Service and all that I am doing right now is
> taking
> out the email name and the domain by string manipulation and getting the
> email ID from
> the database against that. But I am looking for a more proper solution to
> this problem.

> Thanks.
> Aninda
 
Hi Ken,

Thank you very much for your reply with valuable suggestions.

I am very sorry that I missed out on the version of Outlook which sue

asked specifically. Actually I want my code to work in both Outlook 2003

as well as 2007 versions.

Right now it is working only on version Outlook 2007

and not on Outlook 2003 I don't know why. It installs on Outlook 2003

correctly without any installation problem and shows in the plugin section of

outlook 2003 also but never works.

Regards,

Aninda
wrote:


> Sue's on vacation.

> I see a few flaws in your code.

> First of all, in an Outlook COM addin, never create a new
> Outlook.Application object. Always use the Application object passed to you
> in your startup code handler or in OnConnection.

> Second, that code will only look at contacts. If a recipient is from the GAL
> then you never will find anything.

> As Sue recommended it's really best to work with the Recipients collection
> and iterate that. You said that didn't work but didn't provide any
> information as to why. Each Recipient object has an Address property .
> That's what you should be using.

> When the Recipient is part of an Exchange domain you won't get back an SMTP
> style address, you'll get back an Exchange DN type address such as your
> example: /O=DOMAIN/OU=FIRST ADMINISTRATIVE GROUP/CN=RE/ou=abcd.

> In those cases you would need to convert the EX address into an SMTP
> equivalent. Since you never mention which version or versions of Outlook you
> are targeting it's hard to be specific as to how you would convert the
> address. Take a look at
> http://www.outlookcode.com/threads.aspx?forumid=4&messageid=13469 for some
> suggestions as to how to do that. Note that since you're using managed code
> (C#) the CDO option is not available to you, CDO is not supported and should
> not be used with managed code.

> You can also search at www.outlookcode.com using something like "convert
> exchange address to smtp" to look at other forum threads on that topic.

> >

>

> "anindasen_0609" <anindasen0609> wrote in message
> news:88E397B3-696F-41AE-B964-C6C4243AA2C6@microsoft.com...
> > Thanks for your reply. I am sorry I could not reply earlier.
> > 1) I think I created a confusion. I actually meant all the email fields
> > ie., From, To, Cc and Bcc. Wherever there is a name for a particular email
> > address
> > in the local address book, I am getting the name instead of the email ID.
> > My function to get email ID against the name is as below:
> > private string GetEmailID(ref string recipientName)
> > {
> > string recipientEmailID = null;
> > string myQuery = null;
> > myQuery = "[FullName] = '" + recipientName + "'";
> > // Create the Outlook application.
> > Outlook.Application oApp = new Outlook.Application();
> > // Get the NameSpace information.
> > Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
> > // Get the default Contacts folder.
> > Outlook.MAPIFolder oContacts =
> > oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
> > // Get the Items collection from the folder.
> > Outlook.Items oItems = (Outlook.Items)oContacts.Items;
> > // Get the first contact item in the Items collection.
> > Outlook.ContactItem oCt =
> > (Outlook.ContactItem)oItems.Find(myQuery);
> > if (oCt != null)
> > {
> > if (oCt.Email1Address.IndexOf("@") != -1)
> > recipientEmailID = oCt.Email1Address;
> > else
> > recipientEmailID = recipientName;
> > }
> > else
> > {
> > recipientEmailID = recipientName;
> > }
> > oCt = null;
> > oItems = null;
> > oContacts = null;
> > oNS = null;
> > oApp = null;
> > return recipientEmailID;
> > }
> > and I am calling it only when
> > if (emailAddress.IndexOf("@") <= 0)
> > {
> > emailAddress = GetEmailID(ref emailAddress);
> > }
> > 2) I will definitely look at the resources that you have kindly shared and
> > try
> > NewMailEx.
> > 3) There is one more problem which I am solving in a rather inelegant way.
> > I am getting the sender's Email ID from Outlook in a form like:
> > /O=DOMAIN/OU=FIRST ADMINISTRATIVE GROUP/CN=RE/ou=abcd
> > if the email ID is - abcd@domain.com.
> > We are using Active Directory Service and all that I am doing right now is
> > taking
> > out the email name and the domain by string manipulation and getting the
> > email ID from
> > the database against that. But I am looking for a more proper solution to
> > this problem.
> > Thanks.
> > Aninda


>
 
Did you compile the code with a reference to the Outlook/Office 2003 PIA's?

If you did it with references to the Outlook/Office 2007 PIA's it would

never work with Outlook 2003. You always have to compile on the oldest

version of Outlook that you intend to support.

If that's not it you're going to have to do some detective work. You should

put strategically placed logging statements or MessageBox calls to show

where you are in the code, or even if your code is actually loading and

running.

If the code isn't running then you need to do some Fusion debugging, Fusion

is the managed code loader. See

http://blogs.msdn.com/vsod/archive/2008/04/22/Troubleshooting-com-add-in-load-failures.aspx

for information on how to do that.

"anindasen_0609" <anindasen0609> wrote in message

news:FA135F96-390A-446B-BB73-6765AAD899E5@microsoft.com...
> Hi Ken,

> Thank you very much for your reply with valuable suggestions.

> I am very sorry that I missed out on the version of Outlook which sue
> asked specifically. Actually I want my code to work in both Outlook 2003
> as well as 2007 versions.

> Right now it is working only on version Outlook 2007
> and not on Outlook 2003 I don't know why. It installs on Outlook 2003
> correctly without any installation problem and shows in the plugin section
> of
> outlook 2003 also but never works.

> Regards,
> Aninda
 
Thanks Ken and Sue for your help. I now understand propertyaccessor method

and property tags much better because of your help.

I found out a few things which might come to help for people.

In Outlook 2007 - the property tags

which can be accessed with PropertyAccessor method of address entry for

Display Name ("John Doe") = 0x3001001E

EX Address ("/O=DOMAIN/OU=FIRST ADMINISTRATIVE GROUP/CN=RE/ou=John") =

0x803C001E

SMTP Address ("John@DOMAIN.com") = 0x39FE001E

AddressType ("EX" or "SMTP") = 0x3002001E

Regards,

Aninda
wrote:


> Sue's on vacation.

> I see a few flaws in your code.

> First of all, in an Outlook COM addin, never create a new
> Outlook.Application object. Always use the Application object passed to you
> in your startup code handler or in OnConnection.

> Second, that code will only look at contacts. If a recipient is from the GAL
> then you never will find anything.

> As Sue recommended it's really best to work with the Recipients collection
> and iterate that. You said that didn't work but didn't provide any
> information as to why. Each Recipient object has an Address property .
> That's what you should be using.

> When the Recipient is part of an Exchange domain you won't get back an SMTP
> style address, you'll get back an Exchange DN type address such as your
> example: /O=DOMAIN/OU=FIRST ADMINISTRATIVE GROUP/CN=RE/ou=abcd.

> In those cases you would need to convert the EX address into an SMTP
> equivalent. Since you never mention which version or versions of Outlook you
> are targeting it's hard to be specific as to how you would convert the
> address. Take a look at
> http://www.outlookcode.com/threads.aspx?forumid=4&messageid=13469 for some
> suggestions as to how to do that. Note that since you're using managed code
> (C#) the CDO option is not available to you, CDO is not supported and should
> not be used with managed code.

> You can also search at www.outlookcode.com using something like "convert
> exchange address to smtp" to look at other forum threads on that topic.

> >

>

> "anindasen_0609" <anindasen0609> wrote in message
> news:88E397B3-696F-41AE-B964-C6C4243AA2C6@microsoft.com...
> > Thanks for your reply. I am sorry I could not reply earlier.
> > 1) I think I created a confusion. I actually meant all the email fields
> > ie., From, To, Cc and Bcc. Wherever there is a name for a particular email
> > address
> > in the local address book, I am getting the name instead of the email ID.
> > My function to get email ID against the name is as below:
> > private string GetEmailID(ref string recipientName)
> > {
> > string recipientEmailID = null;
> > string myQuery = null;
> > myQuery = "[FullName] = '" + recipientName + "'";
> > // Create the Outlook application.
> > Outlook.Application oApp = new Outlook.Application();
> > // Get the NameSpace information.
> > Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
> > // Get the default Contacts folder.
> > Outlook.MAPIFolder oContacts =
> > oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
> > // Get the Items collection from the folder.
> > Outlook.Items oItems = (Outlook.Items)oContacts.Items;
> > // Get the first contact item in the Items collection.
> > Outlook.ContactItem oCt =
> > (Outlook.ContactItem)oItems.Find(myQuery);
> > if (oCt != null)
> > {
> > if (oCt.Email1Address.IndexOf("@") != -1)
> > recipientEmailID = oCt.Email1Address;
> > else
> > recipientEmailID = recipientName;
> > }
> > else
> > {
> > recipientEmailID = recipientName;
> > }
> > oCt = null;
> > oItems = null;
> > oContacts = null;
> > oNS = null;
> > oApp = null;
> > return recipientEmailID;
> > }
> > and I am calling it only when
> > if (emailAddress.IndexOf("@") <= 0)
> > {
> > emailAddress = GetEmailID(ref emailAddress);
> > }
> > 2) I will definitely look at the resources that you have kindly shared and
> > try
> > NewMailEx.
> > 3) There is one more problem which I am solving in a rather inelegant way.
> > I am getting the sender's Email ID from Outlook in a form like:
> > /O=DOMAIN/OU=FIRST ADMINISTRATIVE GROUP/CN=RE/ou=abcd
> > if the email ID is - abcd@domain.com.
> > We are using Active Directory Service and all that I am doing right now is
> > taking
> > out the email name and the domain by string manipulation and getting the
> > email ID from
> > the database against that. But I am looking for a more proper solution to
> > this problem.
> > Thanks.
> > Aninda


>
 
Hi Ken,

This is about the issue - "Name being returned by the mail object instead of

the Email ID" as I posted earlier.

I iterated through the Global Address List (GAL) as you suggested and

everything is ok as far as getting the email IDs in the GAL is concerned. But

the problem is something else.

There is a particular name that is being returned (Christopher Gillespie)

instead of the email ID which does not exist in any of the address books on

the server side. I think it is kept locally. You must have seen that when you

type an email ID which is not there in outlook, outlook saves it and prompts

it the next time you try to type it. If you double click on it, it pops up a

small form which has the title of "E-mail Properties" and in there you have

the fields "Display Name", "E-mail address", "E-mail type" with a button

called "Custom type" and another field called "Internet format".

I think that is where the display name can be changed and stored. I do not

know where Outlook is storing those email IDs. The guy who is facing the

problem must have changed the email ID of the contact Email ID to a name

("Christopher Gillespie" in this case) and that is what is being returned.

Does it make any sense? I hope it does. Where is outlook saving those

addresses and how can I catch hold of them? Please help.

Regards,

Aninda
wrote:


> Sue's on vacation.

> I see a few flaws in your code.

> First of all, in an Outlook COM addin, never create a new
> Outlook.Application object. Always use the Application object passed to you
> in your startup code handler or in OnConnection.

> Second, that code will only look at contacts. If a recipient is from the GAL
> then you never will find anything.

> As Sue recommended it's really best to work with the Recipients collection
> and iterate that. You said that didn't work but didn't provide any
> information as to why. Each Recipient object has an Address property .
> That's what you should be using.

> When the Recipient is part of an Exchange domain you won't get back an SMTP
> style address, you'll get back an Exchange DN type address such as your
> example: /O=DOMAIN/OU=FIRST ADMINISTRATIVE GROUP/CN=RE/ou=abcd.

> In those cases you would need to convert the EX address into an SMTP
> equivalent. Since you never mention which version or versions of Outlook you
> are targeting it's hard to be specific as to how you would convert the
> address. Take a look at
> http://www.outlookcode.com/threads.aspx?forumid=4&messageid=13469 for some
> suggestions as to how to do that. Note that since you're using managed code
> (C#) the CDO option is not available to you, CDO is not supported and should
> not be used with managed code.

> You can also search at www.outlookcode.com using something like "convert
> exchange address to smtp" to look at other forum threads on that topic.

> >

>

> "anindasen_0609" <anindasen0609> wrote in message
> news:88E397B3-696F-41AE-B964-C6C4243AA2C6@microsoft.com...
> > Thanks for your reply. I am sorry I could not reply earlier.
> > 1) I think I created a confusion. I actually meant all the email fields
> > ie., From, To, Cc and Bcc. Wherever there is a name for a particular email
> > address
> > in the local address book, I am getting the name instead of the email ID.
> > My function to get email ID against the name is as below:
> > private string GetEmailID(ref string recipientName)
> > {
> > string recipientEmailID = null;
> > string myQuery = null;
> > myQuery = "[FullName] = '" + recipientName + "'";
> > // Create the Outlook application.
> > Outlook.Application oApp = new Outlook.Application();
> > // Get the NameSpace information.
> > Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
> > // Get the default Contacts folder.
> > Outlook.MAPIFolder oContacts =
> > oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
> > // Get the Items collection from the folder.
> > Outlook.Items oItems = (Outlook.Items)oContacts.Items;
> > // Get the first contact item in the Items collection.
> > Outlook.ContactItem oCt =
> > (Outlook.ContactItem)oItems.Find(myQuery);
> > if (oCt != null)
> > {
> > if (oCt.Email1Address.IndexOf("@") != -1)
> > recipientEmailID = oCt.Email1Address;
> > else
> > recipientEmailID = recipientName;
> > }
> > else
> > {
> > recipientEmailID = recipientName;
> > }
> > oCt = null;
> > oItems = null;
> > oContacts = null;
> > oNS = null;
> > oApp = null;
> > return recipientEmailID;
> > }
> > and I am calling it only when
> > if (emailAddress.IndexOf("@") <= 0)
> > {
> > emailAddress = GetEmailID(ref emailAddress);
> > }
> > 2) I will definitely look at the resources that you have kindly shared and
> > try
> > NewMailEx.
> > 3) There is one more problem which I am solving in a rather inelegant way.
> > I am getting the sender's Email ID from Outlook in a form like:
> > /O=DOMAIN/OU=FIRST ADMINISTRATIVE GROUP/CN=RE/ou=abcd
> > if the email ID is - abcd@domain.com.
> > We are using Active Directory Service and all that I am doing right now is
> > taking
> > out the email name and the domain by string manipulation and getting the
> > email ID from
> > the database against that. But I am looking for a more proper solution to
> > this problem.
> > Thanks.
> > Aninda


>
 
In continuation with my last post on "Name being returned instead of email

ID" just like to mention that when someone is sending an email who is not in

my address book it is showing in the format of "Christopher Gillespie

[cgillespie@whatever.com]" and when I am hitting on reply to that email, it

is showing "Christopher Gillespie <cgillespie@whatever.com>" in the "To:"

field and if I double click on that email ID it is showing "Christopher

Gillespie" in the display name. I think that is what is being returned when I

am picking up the "To:" address from the sent email object instead of the

email ID.

Regards,

Aninda
wrote:


> Sue's on vacation.

> I see a few flaws in your code.

> First of all, in an Outlook COM addin, never create a new
> Outlook.Application object. Always use the Application object passed to you
> in your startup code handler or in OnConnection.

> Second, that code will only look at contacts. If a recipient is from the GAL
> then you never will find anything.

> As Sue recommended it's really best to work with the Recipients collection
> and iterate that. You said that didn't work but didn't provide any
> information as to why. Each Recipient object has an Address property .
> That's what you should be using.

> When the Recipient is part of an Exchange domain you won't get back an SMTP
> style address, you'll get back an Exchange DN type address such as your
> example: /O=DOMAIN/OU=FIRST ADMINISTRATIVE GROUP/CN=RE/ou=abcd.

> In those cases you would need to convert the EX address into an SMTP
> equivalent. Since you never mention which version or versions of Outlook you
> are targeting it's hard to be specific as to how you would convert the
> address. Take a look at
> http://www.outlookcode.com/threads.aspx?forumid=4&messageid=13469 for some
> suggestions as to how to do that. Note that since you're using managed code
> (C#) the CDO option is not available to you, CDO is not supported and should
> not be used with managed code.

> You can also search at www.outlookcode.com using something like "convert
> exchange address to smtp" to look at other forum threads on that topic.

> >

>

> "anindasen_0609" <anindasen0609> wrote in message
> news:88E397B3-696F-41AE-B964-C6C4243AA2C6@microsoft.com...
> > Thanks for your reply. I am sorry I could not reply earlier.
> > 1) I think I created a confusion. I actually meant all the email fields
> > ie., From, To, Cc and Bcc. Wherever there is a name for a particular email
> > address
> > in the local address book, I am getting the name instead of the email ID.
> > My function to get email ID against the name is as below:
> > private string GetEmailID(ref string recipientName)
> > {
> > string recipientEmailID = null;
> > string myQuery = null;
> > myQuery = "[FullName] = '" + recipientName + "'";
> > // Create the Outlook application.
> > Outlook.Application oApp = new Outlook.Application();
> > // Get the NameSpace information.
> > Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
> > // Get the default Contacts folder.
> > Outlook.MAPIFolder oContacts =
> > oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
> > // Get the Items collection from the folder.
> > Outlook.Items oItems = (Outlook.Items)oContacts.Items;
> > // Get the first contact item in the Items collection.
> > Outlook.ContactItem oCt =
> > (Outlook.ContactItem)oItems.Find(myQuery);
> > if (oCt != null)
> > {
> > if (oCt.Email1Address.IndexOf("@") != -1)
> > recipientEmailID = oCt.Email1Address;
> > else
> > recipientEmailID = recipientName;
> > }
> > else
> > {
> > recipientEmailID = recipientName;
> > }
> > oCt = null;
> > oItems = null;
> > oContacts = null;
> > oNS = null;
> > oApp = null;
> > return recipientEmailID;
> > }
> > and I am calling it only when
> > if (emailAddress.IndexOf("@") <= 0)
> > {
> > emailAddress = GetEmailID(ref emailAddress);
> > }
> > 2) I will definitely look at the resources that you have kindly shared and
> > try
> > NewMailEx.
> > 3) There is one more problem which I am solving in a rather inelegant way.
> > I am getting the sender's Email ID from Outlook in a form like:
> > /O=DOMAIN/OU=FIRST ADMINISTRATIVE GROUP/CN=RE/ou=abcd
> > if the email ID is - abcd@domain.com.
> > We are using Active Directory Service and all that I am doing right now is
> > taking
> > out the email name and the domain by string manipulation and getting the
> > email ID from
> > the database against that. But I am looking for a more proper solution to
> > this problem.
> > Thanks.
> > Aninda


>
 
The To, Cc and Bcc fields can have actual email addresses in them or

"friendly names" such as "John Foobar" or a combination of both. There's no

way to tell, it's just a text field. You can avoid all those problems if you

use the Recipients collection, as both Sue and I have suggested, and use the

Address field of each Recipient object. You will get only an email address

that way, whether or not it's an EX DN or an SMTP type address.

Using the fields you are insisting on using will get you nowhere fast.

"anindasen_0609" <anindasen0609> wrote in message

news:CEC2FE46-1691-48FD-AA89-FD953BC52169@microsoft.com...
> In continuation with my last post on "Name being returned instead of email
> ID" just like to mention that when someone is sending an email who is not
> in
> my address book it is showing in the format of "Christopher Gillespie
> [cgillespie@whatever.com]" and when I am hitting on reply to that email,
> it
> is showing "Christopher Gillespie <cgillespie@whatever.com>" in the "To:"
> field and if I double click on that email ID it is showing "Christopher
> Gillespie" in the display name. I think that is what is being returned
> when I
> am picking up the "To:" address from the sent email object instead of the
> email ID.

> Regards,
> Aninda
 
Thanks Ken. Problem solved.

Regards,

Aninda
wrote:


> The To, Cc and Bcc fields can have actual email addresses in them or
> "friendly names" such as "John Foobar" or a combination of both. There's no
> way to tell, it's just a text field. You can avoid all those problems if you
> use the Recipients collection, as both Sue and I have suggested, and use the
> Address field of each Recipient object. You will get only an email address
> that way, whether or not it's an EX DN or an SMTP type address.

> Using the fields you are insisting on using will get you nowhere fast.

> >

>

> "anindasen_0609" <anindasen0609> wrote in message
> news:CEC2FE46-1691-48FD-AA89-FD953BC52169@microsoft.com...
> > In continuation with my last post on "Name being returned instead of email
> > ID" just like to mention that when someone is sending an email who is not
> > in
> > my address book it is showing in the format of "Christopher Gillespie
> > [cgillespie@whatever.com]" and when I am hitting on reply to that email,
> > it
> > is showing "Christopher Gillespie <cgillespie@whatever.com>" in the "To:"
> > field and if I double click on that email ID it is showing "Christopher
> > Gillespie" in the display name. I think that is what is being returned
> > when I
> > am picking up the "To:" address from the sent email object instead of the
> > email ID.
> > Regards,
> > Aninda


>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
J HELP! Crazy reminder issues Using Outlook 5
S Custom Contact card - need help creating one Outlook VBA and Custom Forms 1
D Lifelong Windows user - new to Mac - Help!!! Using Outlook 3
L Help: set flag for sent mail to check if received an answer Outlook VBA and Custom Forms 2
Nufc1980 Outlook "Please treat this as private label" auto added to some emails - Help. Using Outlook 4
I Help with Smart Folder + Query Builder on IMAP Using Outlook 0
S Outlook 2002- "Send" button has disappeared. Help please. Using Outlook 1
A Outlook 2019 Help with forwarding email without mentioning the previous email sender. Outlook VBA and Custom Forms 0
Witzker Outlook 2019 HELP to get Template Path in a Function Outlook VBA and Custom Forms 2
CWM330 Outlook 365 HELP! Calendar Craziness! Using Outlook 5
S Outlook 365 Help me create a Macro to make some received emails into tasks? Outlook VBA and Custom Forms 1
e_a_g_l_e_p_i Has nobody used Office 2021 enough to help me or have you given up on me.......lol Using Outlook 1
X Open Hyperlinks in an Outlook Email Message (Help with Diane's solution) Outlook VBA and Custom Forms 3
L Help connecting to hosted exchange server 2016 Using Outlook 0
B Seeking help with Outlook rule Using Outlook 2
D Need help with MS Authenticator Using Outlook 4
I Outlook for Mac 2019 using on desktop and laptop IMAP on both need help with folders Using Outlook 1
FryW Need help modifying a VBA script for in coming emails to auto set custom reminder time Outlook VBA and Custom Forms 0
S.Champ Please help? I've imported a random workcalendar I dont even know who's. Can I undo it? and then I need to re-sync the google one again. Its a mess:( Using Outlook 2
S HTML to Plain Text Macro - Help Outlook VBA and Custom Forms 1
e_a_g_l_e_p_i Outlook 2010 Help setting up Gmail account in Outlook 2010 Using Outlook 3
N Help creating a VBA macro with conditional formatting to change the font color of all external emails to red Outlook VBA and Custom Forms 5
Y Filter unread emails in a search folder vba help Outlook VBA and Custom Forms 0
L Need help modifying a VBA script for emails stuck in Outbox Outlook VBA and Custom Forms 6
F Microsoft Outlook Connector 14.0.6123.5001 - Help! Using Outlook 6
Witzker Pls help to change the code for inserting date in Ol contact body Outlook VBA and Custom Forms 5
R Disable conversation thread from replying of recipients in the same subject. Please help Using Outlook 0
R seperate read layout to design in outlook 2016..Help!! Outlook VBA and Custom Forms 3
O Help .. got lost ... installing Office like 2016 Using Outlook 5
A Arthur needs help with 2007 Outlook e-mail Using Outlook.com accounts in Outlook 3
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
Marc2019 Need help please! Cannot Setup my outlook email account on my Mac Outlook 2011 Using Outlook.com accounts in Outlook 2
L Attachment saving and tracking - PLEASE help! Outlook VBA and Custom Forms 5
I Help with dates in task list. Using Outlook 5
C need help setting up outlook first time Using Outlook 1
K To do bar help Using Outlook 8
M Help sending email but removing signature via VBA Outlook VBA and Custom Forms 5
S help with outlook scripting Outlook VBA and Custom Forms 4
J Help Please!!! Outlook 2016 - VBA Macro for replying with attachment in meeting invite Outlook VBA and Custom Forms 9
EmelineGueguen Help to understand the problem of work Using Outlook 1
N Outlook Forms Help Outlook VBA and Custom Forms 2
N Need help syncing contacts to iPhone X Using Outlook 8
S VBA Macro - Run-time error '424': object required - Help Please Outlook VBA and Custom Forms 3
broadbander Needing help with reply/reply all while keeping attachments and adding a new CC recipient. Outlook VBA and Custom Forms 5
J Help! My contacts have disappeared. Using Outlook 5
J HELP- Rule to auto strip prepend from external emails Using Outlook 0
J Help Needed With Multi-Step Login Email Address Using Outlook.com accounts in Outlook 1
G Bcc help - Preventing multiple forwards from a bcc'd distribution group Using Outlook 1
G [Help] Converting array to destination folder path Outlook VBA and Custom Forms 1
K Help.... Office Outlook 2016 Using Outlook 1

Similar threads

Back
Top