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.olFo lderContacts);
// 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 -
.
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, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
"anindasen_0609" wrote in message
news
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(Microsof t.Office.Interop.Outlook.OlDefaultFolders.olFolder Inbox);
m_Items = oMapiFolder.Items;
m_Items.ItemAdd += new
Microsoft.Office.Interop.Outlook.ItemsEvents_ItemA ddEventHandler(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" wrote in
message
...
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
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