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();
But it would seem that if I try to obtain the email address from certain contacts, it comes out abstract:
instead of:
demo@test.org
it will display this:
/O=FIRST ORGANIZATION/OU=EXCHANGE ADMINISTRATIVE GROUP (FYDIBOHF23SP)/CN=RECIPIENTS/CN=TestE<br />
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);
}
public void AccessContacts(string contactName)
{
outlookObj = new Microsoft.Office.Interop.Outlook.Application();
Outlook.MAPIFolder folderContacts = this.outlookObj.ActiveExplorer().Session.
GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
Outlook.Items searchFolder = folderContacts.Items;
int counter = 0;
foreach (Outlook.ContactItem foundContact in searchFolder)
{
if (foundContact.LastName.Contains(contactName))
{
foundContact.Display(false);
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.
Thanks.
(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)