![]() |
Outlook Macro to get Exchange Info from Mail
Hi, I'm working on a macro in Outlook 2003 SP3 that, when started, displays
an Email in a custom dialog, broken down into elements. The dialog is used for Email processing. Upgrading Outlook is not possible, and adding addons is also not possible (other then what is currently installed). What I'm looking to achieve is, when an Email is from Exchange (company email), to display the information found when you right click on the senders name and choose 'Outlook Properties'. Things displayed here, are, for example, the address, country & telephone number. The sender is not in the contacts in Outlook. I want to get the contact information from the Email. I'm accessing the information from the Email with something like this (I have seen that MAPI can be used, but I have not found an example that work like this, if someone can correct me here, I'd be greatful): Dim olkItem As Outlook.MailItem For Each olkItem In Application.ActiveExplorer.Selection 'Read the info and enter it into the dialog 'Example info: MsgBox olkItem.SenderEmailAddress Next How can I access the Exchange information from the mail item? I hope I have explained this clearly enough. Thanks for your time. Office Version:Office 2003 / Operating System:Windows XP |
Outlook Macro to get Exchange Info from Mail
You can get the Exchange Global Address List as a member of the
Outlook.AddressLists collection. You then would have to find the AddressEntry that corresponds to the sender's AddressEntry in the GAL. From there you could get some of the property you refer to, just what's exposed for an AddressEntry. You pretty much would have to iterate the AddressEntries collection in the GAL AddressList to find one where the name matched the AddressEntry.Name property. What is exposed for an AddressEntry does not include telephone numbers, country, mailing address or a lot of other things. For those properties you would need to use other methods such as Extended MAPI or Redemption (www.dimastr.com/redemption) or CDO 1.21 or even LDAP queries. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "_M_a_t_t_" wrote in message ... Hi, I'm working on a macro in Outlook 2003 SP3 that, when started, displays an Email in a custom dialog, broken down into elements. The dialog is used for Email processing. Upgrading Outlook is not possible, and adding addons is also not possible (other then what is currently installed). What I'm looking to achieve is, when an Email is from Exchange (company email), to display the information found when you right click on the senders name and choose 'Outlook Properties'. Things displayed here, are, for example, the address, country & telephone number. The sender is not in the contacts in Outlook. I want to get the contact information from the Email. I'm accessing the information from the Email with something like this (I have seen that MAPI can be used, but I have not found an example that work like this, if someone can correct me here, I'd be greatful): Dim olkItem As Outlook.MailItem For Each olkItem In Application.ActiveExplorer.Selection 'Read the info and enter it into the dialog 'Example info: MsgBox olkItem.SenderEmailAddress Next How can I access the Exchange information from the mail item? I hope I have explained this clearly enough. Thanks for your time. Office Version:Office 2003 / Operating System:Windows XP |
Outlook Macro to get Exchange Info from Mail
Thanks for the answer Ken.
I can not install the redemption Reference, however I do have Microsoft CDO 1.21 Reference. I can also use MAPI. Can you provide an example of how to access the information I'm refering to using either (or both)? In the example I posted, I can access all the elements of Outlook.MailItem. Its the elements of Outlook.ContactItemI'm wanting to access from the Email only, and I can not find a way nor an example of how to do this. Only on how to access the information from the contact (Contacts saved in Outlook Address Book locally) from Outlook.ContactItem via address book. "Ken Slovak - [MVP - Outlook]" wrote: You can get the Exchange Global Address List as a member of the Outlook.AddressLists collection. You then would have to find the AddressEntry that corresponds to the sender's AddressEntry in the GAL. From there you could get some of the property you refer to, just what's exposed for an AddressEntry. You pretty much would have to iterate the AddressEntries collection in the GAL AddressList to find one where the name matched the AddressEntry.Name property. What is exposed for an AddressEntry does not include telephone numbers, country, mailing address or a lot of other things. For those properties you would need to use other methods such as Extended MAPI or Redemption (www.dimastr.com/redemption) or CDO 1.21 or even LDAP queries. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "_M_a_t_t_" wrote in message ... Hi, I'm working on a macro in Outlook 2003 SP3 that, when started, displays an Email in a custom dialog, broken down into elements. The dialog is used for Email processing. Upgrading Outlook is not possible, and adding addons is also not possible (other then what is currently installed). What I'm looking to achieve is, when an Email is from Exchange (company email), to display the information found when you right click on the senders name and choose 'Outlook Properties'. Things displayed here, are, for example, the address, country & telephone number. The sender is not in the contacts in Outlook. I want to get the contact information from the Email. I'm accessing the information from the Email with something like this (I have seen that MAPI can be used, but I have not found an example that work like this, if someone can correct me here, I'd be greatful): Dim olkItem As Outlook.MailItem For Each olkItem In Application.ActiveExplorer.Selection 'Read the info and enter it into the dialog 'Example info: MsgBox olkItem.SenderEmailAddress Next How can I access the Exchange information from the mail item? I hope I have explained this clearly enough. Thanks for your time. Office Version:Office 2003 / Operating System:Windows XP . |
Outlook Macro to get Exchange Info from Mail
For MAPI you'd need to use the IAddressBook interface, but I'm not a MAPI
programmer so you can see if Dmitry sees this, start another thread that might catch his attention, or post in microsoft.public.win32.programmer.messaging (which is a group for MAPI programmers). I haven't done any CDO coding in probably almost 8 years, I couldn't help with that. You might find something relevant at www.cdolive.com, either in the sample snippets or sample projects. Sig had a lot of valuable stuff there, but with Redemption I just don't use CDO because of the highly restricted security environment in client side CDO. Server side CDO is not restricted in the same way. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "_M_a_t_t_" wrote in message ... Thanks for the answer Ken. I can not install the redemption Reference, however I do have Microsoft CDO 1.21 Reference. I can also use MAPI. Can you provide an example of how to access the information I'm refering to using either (or both)? In the example I posted, I can access all the elements of Outlook.MailItem. Its the elements of Outlook.ContactItemI'm wanting to access from the only, and I can not find a way nor an example of how to do this. Only on how to access the information from the contact (Contacts saved in Outlook Address Book locally) from Outlook.ContactItem via address book. |
Outlook Macro to get Exchange Info from Mail
So d oyo uwant to access EX specific properties of a contact that was create
in the hContacts folder from one of the GAL entries? Or EX properties of a message sender/recipient? -- Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool - "_M_a_t_t_" wrote in message ... Thanks for the answer Ken. I can not install the redemption Reference, however I do have Microsoft CDO 1.21 Reference. I can also use MAPI. Can you provide an example of how to access the information I'm refering to using either (or both)? In the example I posted, I can access all the elements of Outlook.MailItem. Its the elements of Outlook.ContactItemI'm wanting to access from the only, and I can not find a way nor an example of how to do this. Only on how to access the information from the contact (Contacts saved in Outlook Address Book locally) from Outlook.ContactItem via address book. "Ken Slovak - [MVP - Outlook]" wrote: You can get the Exchange Global Address List as a member of the Outlook.AddressLists collection. You then would have to find the AddressEntry that corresponds to the sender's AddressEntry in the GAL. From there you could get some of the property you refer to, just what's exposed for an AddressEntry. You pretty much would have to iterate the AddressEntries collection in the GAL AddressList to find one where the name matched the AddressEntry.Name property. What is exposed for an AddressEntry does not include telephone numbers, country, mailing address or a lot of other things. For those properties you would need to use other methods such as Extended MAPI or Redemption (www.dimastr.com/redemption) or CDO 1.21 or even LDAP queries. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "_M_a_t_t_" wrote in message ... Hi, I'm working on a macro in Outlook 2003 SP3 that, when started, displays an Email in a custom dialog, broken down into elements. The dialog is used for Email processing. Upgrading Outlook is not possible, and adding addons is also not possible (other then what is currently installed). What I'm looking to achieve is, when an Email is from Exchange (company email), to display the information found when you right click on the senders name and choose 'Outlook Properties'. Things displayed here, are, for example, the address, country & telephone number. The sender is not in the contacts in Outlook. I want to get the contact information from the Email. I'm accessing the information from the Email with something like this (I have seen that MAPI can be used, but I have not found an example that work like this, if someone can correct me here, I'd be greatful): Dim olkItem As Outlook.MailItem For Each olkItem In Application.ActiveExplorer.Selection 'Read the info and enter it into the dialog 'Example info: MsgBox olkItem.SenderEmailAddress Next How can I access the Exchange information from the mail item? I hope I have explained this clearly enough. Thanks for your time. Office Version:Office 2003 / Operating System:Windows XP . |
Outlook Macro to get Exchange Info from Mail
The contact does not exist in the local address book. What I want to access
is the contact information you can access when right clicking on From name and choosing Outlook Properties. With non exchange senders, you Display name, E-mail address, E-mail type, and Internet format. When its an Exchange mail, you get (provided entered), shipping address, phone number(s), country etc. Its this information I'd like to access directly from the Email (as the contact isn't in the local address book, and I'm reading in, parcing and displaying information from the email). However, I can not install additional plug-ins. I need to be able to do this with what Outlook already has. I'm assuming this can be done with Microsoft CDO 1.21 Reference and/or MAPI, but I need an example of how to access the information from the email and contact in 1 loop (or perhaps via a sub function called from the main loop. Again I'm currently using this formation to read out the information from the Email: Dim olkItem As Outlook.MailItem For Each olkItem In Application.ActiveExplorer.Selection 'Read the info and enter it into the dialog 'Example info: MsgBox olkItem.SenderEmailAddress Next And this works fine (as long as only 1 mail is selected, more then one causes problems, since each would be processed, but only the last selected would actually be displayed). Matt "Dmitry Streblechenko" wrote: So d oyo uwant to access EX specific properties of a contact that was create in the hContacts folder from one of the GAL entries? Or EX properties of a message sender/recipient? -- Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool - |
Outlook Macro to get Exchange Info from Mail
Any chance of an update on this? I have not been ale to find any information
on the Web or in the Help file.... |
Outlook Macro to get Exchange Info from Mail
-- Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool - "_M_a_t_t_" wrote in message ... The contact does not exist in the local address book. What I want to access is the contact information you can access when right clicking on From name and choosing Outlook Properties. With non exchange senders, you Display name, E-mail address, E-mail type, and Internet format. When its an Exchange mail, you get (provided entered), shipping address, phone number(s), country etc. Its this information I'd like to access directly from the Email (as the contact isn't in the local address book, and I'm reading in, parcing and displaying information from the email). However, I can not install additional plug-ins. I need to be able to do this with what Outlook already has. I'm assuming this can be done with Microsoft CDO 1.21 Reference and/or MAPI, but I need an example of how to access the information from the email and contact in 1 loop (or perhaps via a sub function called from the main loop. Again I'm currently using this formation to read out the information from the Email: Dim olkItem As Outlook.MailItem For Each olkItem In Application.ActiveExplorer.Selection 'Read the info and enter it into the dialog 'Example info: MsgBox olkItem.SenderEmailAddress Next And this works fine (as long as only 1 mail is selected, more then one causes problems, since each would be processed, but only the last selected would actually be displayed). Matt "Dmitry Streblechenko" wrote: So d oyo uwant to access EX specific properties of a contact that was create in the hContacts folder from one of the GAL entries? Or EX properties of a message sender/recipient? -- Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool - |
Outlook Macro to get Exchange Info from Mail
Create an instance of the MAPI.Session object,
set Session.MAPIOBJECT property to Namespace.MAPIOBJECT from OOM Reopen the message in CDO 1.21 using Session.GetMessage and the valeu of teh MailItem.EntryID Read the Message.Sender property (returnsd AddressEntry). Use AddressEntry.Fields[] to access the required propeties - you can get the props tags from OutlookSpy (e.g. click IMAPISession | QueryIdentity) -- Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool - "_M_a_t_t_" wrote in message ... The contact does not exist in the local address book. What I want to access is the contact information you can access when right clicking on From name and choosing Outlook Properties. With non exchange senders, you Display name, E-mail address, E-mail type, and Internet format. When its an Exchange mail, you get (provided entered), shipping address, phone number(s), country etc. Its this information I'd like to access directly from the Email (as the contact isn't in the local address book, and I'm reading in, parcing and displaying information from the email). However, I can not install additional plug-ins. I need to be able to do this with what Outlook already has. I'm assuming this can be done with Microsoft CDO 1.21 Reference and/or MAPI, but I need an example of how to access the information from the email and contact in 1 loop (or perhaps via a sub function called from the main loop. Again I'm currently using this formation to read out the information from the Email: Dim olkItem As Outlook.MailItem For Each olkItem In Application.ActiveExplorer.Selection 'Read the info and enter it into the dialog 'Example info: MsgBox olkItem.SenderEmailAddress Next And this works fine (as long as only 1 mail is selected, more then one causes problems, since each would be processed, but only the last selected would actually be displayed). Matt "Dmitry Streblechenko" wrote: So d oyo uwant to access EX specific properties of a contact that was create in the hContacts folder from one of the GAL entries? Or EX properties of a message sender/recipient? -- Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool - |
Outlook Macro to get Exchange Info from Mail
Thanks for the update Dmitry, however I do not understand what you are
refering to nor how to do what you have stated (I say that I need an example previously) ..... Any chance you can post a small example? |
Outlook Macro to get Exchange Info from Mail
I don't have CDO 1.21 installed here, so the script below uses Redemption
set Session = CreateObject("Redemption.RDOSession") Session.MAPIOBJECT = Application.Session.MAPIOBJECT for each Item in Application.ActiveExplorer.Selection set RDOItem = Session.GetMessagefromID(Item.EntryID) set Sender = RDOItem.Sender if not (Sender Is Nothing) Then MsgBox Sender.City end if next The next script is using CDO 1.21, but I did not have a chance to actually test it set Session = CreateObject("MAPI.Session") Session.MAPIOBJECT = Application.Session.MAPIOBJECT for each Item in Application.ActiveExplorer.Selection set CDOItem = Session.GetMessage(Item.EntryID) set Sender = CDOItem.Sender if not (Sender Is Nothing) Then MsgBox Sender.City end if next -- Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool - "_M_a_t_t_" wrote in message ... Thanks for the update Dmitry, however I do not understand what you are refering to nor how to do what you have stated (I say that I need an example previously) ..... Any chance you can post a small example? |
Outlook Macro to get Exchange Info from Mail
Thanks Dmitry, regretfully the CDO example doesn't work... I get an error on
MAPIOBJECT: "Method or data member not found (Error 461)".... |
Outlook Macro to get Exchange Info from Mail
Do you get that error on reading the Application.Session.MAPIOBJECT or
setting the Session.MAPIOBJECT property. Where does your code run? -- Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool - "_M_a_t_t_" wrote in message ... Thanks Dmitry, regretfully the CDO example doesn't work... I get an error on MAPIOBJECT: "Method or data member not found (Error 461)".... |
Outlook Macro to get Exchange Info from Mail
I get the error on:
Session.MAPIOBJECT = Application.Session.MAPIOBJECT Regretfully the help isn't 'helpful' here, since I can't find any information about this, or what would be 'correct'..... |
Outlook Macro to get Exchange Info from Mail
That line contains two statements. One is reading the property. Another one
is setting it. Can you break that line in two to see which one fails? set temp = Application.Session.MAPIOBJECT Session.MAPIOBJECT = temp Is this Access? If, Session intrinsic variable points to an Access object. Rename the Session variable in the script to somethign like CDOSession. -- Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool - "_M_a_t_t_" wrote in message ... I get the error on: Session.MAPIOBJECT = Application.Session.MAPIOBJECT Regretfully the help isn't 'helpful' here, since I can't find any information about this, or what would be 'correct'..... |
Outlook Macro to get Exchange Info from Mail
Again, where does your code run?
I'm trying to get this working on Outlook 2003 (11.8313.8221) SP3. Another words, Outlook VBA (Alt-F11 in Outlook). |
Outlook Macro to get Exchange Info from Mail
Session is also an intrinsic variable in VBA. Try the following (it does
work) PR_LOCALITY = &H3A27001E Set cdoSession = CreateObject("MAPI.Session") Set temp = Application.Session.MAPIOBJECT cdoSession.MAPIOBJECT = temp For Each Item In Application.ActiveExplorer.Selection Set CDOItem = cdoSession.GetMessage(Item.EntryID) Set Sender = CDOItem.Sender If Not (Sender Is Nothing) Then Set Field = Sender.Fields.Item(PR_LOCALITY) If Not (Field Is Nothing) Then MsgBox Field.Value End If End If Next -- Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool - "_M_a_t_t_" wrote in message ... Again, where does your code run? I'm trying to get this working on Outlook 2003 (11.8313.8221) SP3. Another words, Outlook VBA (Alt-F11 in Outlook). |
Outlook Macro to get Exchange Info from Mail
Hopfully this reply is posted. Tried several time, and for some reason its
not posting. When I run the code you posted above I get: Compile error: Assignment to constant not permitted on this line: Set CdoSession = CreateObject("MAPI.Session") |
Outlook Macro to get Exchange Info from Mail
Try setting a reference to CDO.DLL in the references for your VBA project.
-- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "_M_a_t_t_" wrote in message ... Hopfully this reply is posted. Tried several time, and for some reason its not posting. When I run the code you posted above I get: Compile error: Assignment to constant not permitted on this line: Set CdoSession = CreateObject("MAPI.Session") |
Outlook Macro to get Exchange Info from Mail
Hi Ken,
Try setting a reference to CDO.DLL in the references for your VBA project. I have this already: Microsoft CDO 1.21 Library C:\Program Files\Common Files\System\MSMAPI\1033\CDO.DLL I'm starting to think this isn't possible....... |
Outlook Macro to get Exchange Info from Mail
Hi Ken,
Try setting a reference to CDO.DLL in the references for your VBA project. I have this already: Microsoft CDO 1.21 Library C:\Program Files\Common Files\System\MSMAPI\1033\CDO.DLL I'm starting to think this isn't possible...... |
Outlook Macro to get Exchange Info from Mail
Hi Ken,
Try setting a reference to CDO.DLL in the references for your VBA project. I have this already: Microsoft CDO 1.21 Library C:\Program Files\Common Files\System\MSMAPI\1033\CDO.DLL I'm starting to think this isn't possible...... |
Outlook Macro to get Exchange Info from Mail
Found the/a solution.
Adding Option Explicit to the head of the Module, and then Diming each variable finally got results. Wish someone had mentioned this.... This now brings me to my next two questions: 1. How to go though each element and not cause an error message to be displayed when nothing is there (for example if CdoPR_BUSINESS_ADDRESS_POSTAL_CODE is empty, I get an error that allows me to End or Debug. I'd like to skip this, and just leave it empty)? 2. How to desable to prompt from Outlook asking if I want to allow the macro to access: A program is trying to access e-mail addresses you have stored in Outlook. Do you want to allow this? I can only allow 1, 2, 5 & 10 Minutes. But not an always allow. I have digitally signed the macros, and all work without prompting until CDO is accessed, then the prompt appears. |
Outlook Macro to get Exchange Info from Mail
For 1 you'd add an On Error Resume Next statement and check for IsEmpty() on
the property and check for an error. If you have either you can clear the error and just move on. For 2 that's the reason most of stopped using CDO many years ago, the security. Client side CDO actually has tighter security than the Outlook object model (server side CDO has none of the security but should not be installed where Outlook is installed). There are hacks and kludges such as ExpressClickYes, but I'd rather not use things like that. As a substitute for CDO most of us have moved on to using Redemption. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Professional Programming Outlook 2007. Reminder Manager, Extended Reminders, Attachment Options. http://www.slovaktech.com/products.htm "_M_a_t_t_" wrote in message ... Found the/a solution. Adding Option Explicit to the head of the Module, and then Diming each variable finally got results. Wish someone had mentioned this.... This now brings me to my next two questions: 1. How to go though each element and not cause an error message to be displayed when nothing is there (for example if CdoPR_BUSINESS_ADDRESS_POSTAL_CODE is empty, I get an error that allows me to End or Debug. I'd like to skip this, and just leave it empty)? 2. How to desable to prompt from Outlook asking if I want to allow the macro to access: A program is trying to access e-mail addresses you have stored in Outlook. Do you want to allow this? I can only allow 1, 2, 5 & 10 Minutes. But not an always allow. I have digitally signed the macros, and all work without prompting until CDO is accessed, then the prompt appears. |
All times are GMT +1. The time now is 09:39 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com