Is there anyway in VB, using the outlook object, to get the e-mail address for a given alias?
Help please.
Kev.:afrog:
Printable View
Is there anyway in VB, using the outlook object, to get the e-mail address for a given alias?
Help please.
Kev.:afrog:
You mean the 'Display As' for a ContactItem?
Nope. In the properties there is an alias field. In our case we hold the user id there and that is what I want to search on to get the address.
Can it be done?
Coz I can't find anything??
I take it that this is a custom field? In MailItem or ContactItem?
Anything can be do if you have the persistance and patience.
Nope, as far as I know it's not a custom field. It's a field in the address book properties.
Ah! Its not really the Address book, its the Global Address List. There
is no Alias field or property for a Contact, but let me whip up
something for this then.
http://www.vbforums.com/attachment.p...postid=1789700
Not possible with OOM. You need to use CDO in order to access
that property. Is using CDO a possibility for you?
@%@$%, my vb crashed on the demo I had just finished for you
using CDO. When I get home tonight I will re-write it and post it.
It works great! Wish I had done a save. :cry:
I had it loading the entire GAL and showing all the Alias' and
email addresses. Even had a double click on the listview to bring
up the details of the Address Entry.
Oh well.
I really don't know anything about CDO!?
But we can use it I think!!!
Well here it is in case you can use CDO. If you did a full install of
Outlook it should be installed already. If not you can install it from
the Outlook CD. Its Microsoft Collaboration Data Objects 1.21.
For client applications, you must install Outlook in order to install
CDO. In Outlook 2000 and later versions, CDO is included with
Outlook but is not part of the default setup, nor will it install on
first run. Therefore, you must explicitly select it during a custom
setup or use the Windows Installer object library to
programmatically install CDO
I cleared out some of the names and blocked the email address
from showing so they wont get spammed just in case, but it does
fillup the listview.
http://www.vbforums.com/attachment.p...postid=1790882
:D :D :DVB Code:
Option Explicit 'Add reference to MS CDO 1.21 Library 'Add reference to MS Office Outlook xx.x Object Library 'Add listview control (lvwGAL) 'Project > Components > MS Windows Common Controls 6.0 'Add 2 command buttons (cmdClose) and (cmdRefresh) Private moApp As Outlook.Application Private moNS As Outlook.NameSpace Private moCDO As MAPI.Session Private Const cdoPR_DISPLAY_NAME As Long = &H3001001E Private Const cdoPR_ACCOUNT As Long = &H3A00001E Private Const cdoPR_GIVEN_NAME As Long = &H3A06001E Private Const cdoPR_SURNAME As Long = &H3A11001E Private Const cdoPR_EMAIL As Long = &H39FE001E Private Sub cmdClose_Click() Unload Me End Sub Private Sub cmdRefresh_Click() GetAddressCDO End Sub Private Sub Form_Load() On Error GoTo No_Bugs 'INITIALIZE OOM (JUST SO CDO CAN LOGON TO INSTANCE) Set moApp = GetObject(, "Outlook.Application") If TypeName(moApp) = "Nothing" Then Set moApp = New Outlook.Application End If Set moNS = moApp.GetNamespace("MAPI") 'INITIALIZE CDO Set moCDO = CreateObject("MAPI.Session") moCDO.Logon "", "", False, False 'INITIALIZE LISTVIEW With lvwGAL .FullRowSelect = True .LabelEdit = lvwManual .MultiSelect = False .View = lvwReport .ColumnHeaders.Add , , "", 0 .ColumnHeaders.Add , , "Display Name", (.Width / 5) - 70 .ColumnHeaders.Add , , "Last Name", (.Width / 5) - 70 .ColumnHeaders.Add , , "First Name", (.Width / 5) - 70 .ColumnHeaders.Add , , "Alias", (.Width / 5) - 70 .ColumnHeaders.Add , , "E-Mail", (.Width / 5) - 70 .Sorted = True .SortOrder = lvwAscending .SortKey = 1 End With 'POPULATE LISTVIEW GetAddressCDO Exit Sub No_Bugs: If Err.Number = 429 Then Resume Next Else MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation End If End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) moCDO.Logoff Set moCDO = Nothing Set moNS = Nothing Set moApp = Nothing End Sub Private Sub lvwGAL_DblClick() On Error Resume Next Dim oDetails As Object Set oDetails = moCDO.GetAddressEntry(lvwGAL.SelectedItem) oDetails.Details Set oDetails = Nothing End Sub Private Sub GetAddressCDO() On Error GoTo No_Bugs Dim oAEntries As Object Dim oAEntry As Object Dim oFields As Object Dim lvItm As ListItem Dim i As Integer Dim ii As Integer Dim iii As Integer Dim vDetails As Variant Dim lRet As Long lvwGAL.ListItems.Clear Set oAEntries = moCDO.AddressLists.Item("Global Address List").AddressEntries For i = 1 To oAEntries.Count Set oAEntry = oAEntries.Item(i) Set lvItm = lvwGAL.ListItems.Add(, , oAEntry.ID) 'ITERATE THROUGH ALL FIELDS OF THIS ADDRESS ENTRY For ii = 1 To oAEntry.Fields.Count Set oFields = oAEntry.Fields(ii) vDetails = oFields.Value On Error Resume Next lRet = UBound(vDetails) If Err.Number = 0 Then 'ITERATE THROUGH ALL VALUES FOR THIS ARRAY For iii = 0 To UBound(vDetails) 'Debug.Print "Field ID: " & oFields.ID & "; Field Array #" & iii & ";Value: " & vDetails(iii) Next Else 'ADD SINGLE VALUES TO THE LISTVIEW If oFields.ID = cdoPR_DISPLAY_NAME Then lvItm.SubItems(1) = vDetails ElseIf oFields.ID = cdoPR_SURNAME Then lvItm.SubItems(2) = vDetails ElseIf oFields.ID = cdoPR_GIVEN_NAME Then lvItm.SubItems(3) = vDetails ElseIf oFields.ID = cdoPR_ACCOUNT Then lvItm.SubItems(4) = vDetails ElseIf oFields.ID = cdoPR_EMAIL Then lvItm.SubItems(5) = vDetails End If 'Debug.Print "Field ID: " & oFields.ID & "; Value " & vDetails End If Next Set lvItm = Nothing Next Set oAEntries = Nothing Set oAEntry = Nothing Set oFields = Nothing Exit Sub No_Bugs: MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation End Sub
VB/Outlook Guru!!!
Spoken like a true code warrior.Quote:
Originally posted by RobDog888
Anything can be do if you have the persistance and patience.
Actually I finished the re-write after the crash yesterday. It took
me about 30 minutes to do this. I just didn't have the time to
make it look nice and post because I was on overtime and I had
to go home.
Although the one issue is still the security popup, but I wrote
something this morning that I like to call "Outlook® Security
Prompt Dismisser™" or "DismissMe™" coming to a download site
near you soon. It took me about an hour to figure out that M$
placed a block on the message stream preventing the security
prompt from being automated in later versions of Outlook. But I
found a way around it in about another hour or so. Actually very
simple. M$ can't do anything about it either :D
VB/Outlook Guru!
Hey Robdog, I tried ur above code.
I have added reference to cdo 1.21
But its giving me error.
Run-time error'2147219963(80040605)
Collaboration Data Objects-[MAP_E_Not_INITIALIZED(80040605)]]
What i have to do if i want only firstname and lastname in a listview?
Thanks!
Hi RobDog,
That sample code works perfectly. However, i'm trying to get the data from an exchange 2000 server with 51k entries which obviously takes quite a bit of time (over 10 mins). The good news is that our lists are broken down into different groups,and I need to get the address list for IRELAND-->Receipients.
I've tried variations on /vbcode "Set oAEntries = moCDO.AddressLists.Item("Flextronics.IRELAND.Recipients").AddressEntries" /endvbcode
but i get the error:
-2147221233 - [Collaboration Data Objects - [MAPI_E_NOT_FOUND(8004010F)]].
Any help would be appreciated,
thanks
i got a lot of error of this source code ...>__< is it wrote by VB 03 ?
would you mind sending me the souce code to translate to VB 05 ?
I sent you a reply in your PM. ;)
Basically, this code is VB 6 and CDO 1.21 which are not compatible with VB.NET. ;)
I'll try to get a .NET version out this week sometime when I have some free time. :)
Ps, I will add it to my FAQ, when I can this week, that I will be publishing in the Office Development forum tomorrow hopefully.
Great code, Rob. Did you ever post your dismisser? A search on DismissMe doesn't find anything, not even this post of yours.Quote:
Originally Posted by RobDog888
No I didnt because I needed to change it for protection of disassembly of the exe/dll and add a program registration scheme. Another project that I hopefully will be getting done real soon too. My delimma is if I should make it freeware or commercial and charge a very small fee for it? Would anyone pay $ for it when there is at least one other similar product for free?
Any further progress? I'm looking at developing an automated mailer in VB6 and that Outlook message is a real PITA.
There are other ways to send email in VB6 without even using outlook - look into CDO.
CDO will also generate the security popup.
I have the code on my server but I havent had time to replace the crashed hd and recover the data.
:check:thank you all of guys, i have done it
Dim mail As MailItem
Dim insp As Inspector
Set insp = Application.ActiveInspector
Set mail = insp.CurrentItem
Debug.Print mail.To
Hi Rob,
Stupid question time... Is there a form that you created to use the code you have provided?
Can you provide an example at all?
I have the exact same problem as the OP and this code should solve the problem for me... I hope.
Thanks!!
You mean post #11?
Its VB6 code and you just have to create a new form and drop the code in and create the buttons and controls as mentioned in the commented code :)