Click here to Skip to main content
15,880,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey Guys

Okay I am not sure if there is a clear way to really state this question, but I'll do my best and give as much information as possible.

I wrote a C# program that adds a ribbon to the ribbon tab to outlook 2010 and enables me to integrate selected data into my database, for example build my own contact, email etc almost like an address book, but with extra information that are useful for the flow of day to day activities.

So far I have everything going for me, but there's a problem with the value of the email addresses sometimes. If I receive an email from a gmail account or another type of account, it pulls through perfectly using this code:

 Outlook.MailItem mailItem = (selectedObject as Outlook.MailItem);
string email = "";
email = mailItem.SenderEmailAddress.ToString(); //added ToString() to see if that changes anything... it doesn't (OO')

But it would seem that if I try to obtain the email address from certain contacts, it comes out abstract:

instead of:
it will display this:
with the 'TestE' being the start of the email address.

naturally I assumed it is due to the fact that it is an exchange server/mail account.

but when I sat up office on a different PC and tested this again, the email address pulled through perfectly. So I have tried bypassing the method by getting the email address from the contact list in outlook as follows:
if (email.Contains("/";))
       AccessContacts(contact); //contact variable contains name and surname of sender


public void AccessContacts(string contactName)
           outlookObj = new Microsoft.Office.Interop.Outlook.Application();
            Outlook.MAPIFolder folderContacts = this.outlookObj.ActiveExplorer().Session.
            Outlook.Items searchFolder = folderContacts.Items;
            int counter = 0;
            foreach (Outlook.ContactItem foundContact in searchFolder)
                if (foundContact.LastName.Contains(contactName))
                    counter = counter + 1;
            MessageBox.Show("You have " + counter +
                " contacts with last names that contain "
                + contactName + ".");

but I keep getting errors and problems... I am still new to programming, so it's possible I'm just doing something unlogical in my code... cause I am currently a little overloaded with work and typed a lot of this in a rush.

Please is there anyway you can help me? If you need more information or anything let me know. I have tried everything I can think of.


(I have searched everywhere for help on this, but mostly it seems there is only help for visual studio 2013, and i am aware that it comes with an epic tool that apparently makes this kind of task easier, but it's only Oulook 2013 compatible, and i need it for Outlook 2010)
Updated 15-May-14 2:11am
José Amílcar Casimiro 15-May-14 12:51pm    
Read this article:
Star_Rookie 16-May-14 4:28am    
Thanks so much, I will check it out when I get a moment and let you know if this solved my problem, cause it looks promising. =)
Star_Rookie 19-Jun-14 3:50am    
Hi José, i have managed to figure out a way around this whole mumble jumble, but your link was most helpful, i really do appreciate the help and think it will be alright to mark this question as resolved as it is kinda resolved now =)
José Amílcar Casimiro 19-Jun-14 11:25am    
Great. Good Job.

1 solution

This Question has been solved, a good place for referencing is the page José Amílcar Ferreira Casimiro gave in the comments. =) thanks for all the help.

EDIT:[VICK]... Link Added from the comment here.

Read this article:
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900