VB6 - Look up email address from outlook address book?

Reply

Join Date: Jul 2007
Posts: 113
Reputation: tgifgemini is an unknown quantity at this point 
Solved Threads: 0
tgifgemini tgifgemini is offline Offline
Junior Poster

VB6 - Look up email address from outlook address book?

 
0
  #1
Jul 20th, 2007
Hello everyone,
is there a posibility that I can look up email addresses from outlook email address book instead of accepting email address from an inputbox or hard-coding it?
See my codes below:
Thanks.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. SENDEMAIL:
  3. Set OutlookApp = CreateObject("Outlook.Application")
  4. Set OutlookMail = OutlookApp.CreateItem(0)
  5.  
  6. OutlookMail.To = EmailID
  7. OutlookMail.Subject = "Project Status"
  8. OutlookMail.Body = "This is VB email test"
  9.  
  10. If Len(MailAttach) = 0 Then
  11. OutlookMail.Attachments.Add MailAttach '"C:\ProjectStatus.xls"
  12. End If

tgifgemini
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 166
Reputation: AV Manoharan is an unknown quantity at this point 
Solved Threads: 9
AV Manoharan AV Manoharan is offline Offline
Junior Poster

Re: VB6 - Look up email address from outlook address book?

 
0
  #2
Jul 21st, 2007
Originally Posted by tgifgemini View Post
Hello everyone,
is there a posibility that I can look up email addresses from outlook email address book instead of accepting email address from an inputbox or hard-coding it?
See my codes below:
Thanks.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. SENDEMAIL:
  3. Set OutlookApp = CreateObject("Outlook.Application")
  4. Set OutlookMail = OutlookApp.CreateItem(0)
  5.  
  6. OutlookMail.To = EmailID
  7. OutlookMail.Subject = "Project Status"
  8. OutlookMail.Body = "This is VB email test"
  9.  
  10. If Len(MailAttach) = 0 Then
  11. OutlookMail.Attachments.Add MailAttach '"C:\ProjectStatus.xls"
  12. End If

tgifgemini
Answer = No as well as Yes.

No means not directly and Yes means indirectly.

Why not directly ? Because it exposes the address book to hackers very easily.

How indirectly ? There is a Outlook Express API (OEAPI) developed by third parties which you can use it, not only in VB but also in host of other programming languages.

If you are a very advanced programmer you would be knowing it already or else while you approach to that category you will come across with it.

Be contended now and get back to me later.

Happy programming

regards
AV Manoharan
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: VB6 - Look up email address from outlook address book?

 
0
  #3
Jul 23rd, 2007
Hi tgif,

Add a Listbox to the form and
use this code:

Option Explicit
Dim ola As Outlook.AddressList
Dim ole As Outlook.AddressEntry
List1.Clear
Private Sub address_book_Click()
On Error Resume Next
Set ola = Application.Session.AddressLists("MyContacts") 
For Each ole In ola.AddressEntries
    List1.AddItem ole
Next
Set ola = Nothing
Set ole = Nothing
End Sub

In above code, change MyContacts to the name of ur Address Book.

Regards
Veena
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 166
Reputation: AV Manoharan is an unknown quantity at this point 
Solved Threads: 9
AV Manoharan AV Manoharan is offline Offline
Junior Poster

Re: VB6 - Look up email address from outlook address book?

 
0
  #4
Jul 23rd, 2007
Originally Posted by QVeen72 View Post
Hi tgif,

Add a Listbox to the form and
use this code:

Option Explicit
Dim ola As Outlook.AddressList
Dim ole As Outlook.AddressEntry
List1.Clear
Private Sub address_book_Click()
On Error Resume Next
Set ola = Application.Session.AddressLists("MyContacts") 
For Each ole In ola.AddressEntries
   List1.AddItem ole
Next
Set ola = Nothing
Set ole = Nothing
End Sub

In above code, change MyContacts to the name of ur Address Book.

Regards
Veena
Veena, It is not his addressbook he wants. He wants address book of outlook express. Please help him to find out!
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: VB6 - Look up email address from outlook address book?

 
0
  #5
Jul 23rd, 2007
Hi tgif,

If u dont know the Address Book name, u can loop thru all the AddressBooks and List It,
Add a "ListView" Control to ur form and rename it as "lvw", Check this code:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub FillListView()
  2.  
  3. Dim olApp As Outlook.Application
  4. Dim olNS As Outlook.NameSpace
  5. Dim olAL As Outlook.AddressList
  6. Dim olAE As Outlook.AddressEntry
  7. Dim olMail As Outlook.MailItem
  8.  
  9. Set olApp = New Outlook.Application
  10. Set olNS = olApp.GetNamespace("MAPI")
  11. For Each olAL In olNS.AddressLists
  12. For Each olAE In olAL.AddressEntries
  13. lvw.ListItems.Add , , olAE.Name
  14. lvw.ListItems(lvw.ListItems.Count).SubItems(1) = olAE.Address
  15. lvw.ListItems(lvw.ListItems.Count).SubItems(2) = olAE.ID
  16. lvw.ListItems(lvw.ListItems.Count).Tag = olAE.ID
  17. Next
  18. Next
  19. End Sub

REgards
Veena
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 113
Reputation: tgifgemini is an unknown quantity at this point 
Solved Threads: 0
tgifgemini tgifgemini is offline Offline
Junior Poster

Re: VB6 - Look up email address from outlook address book?

 
0
  #6
Jul 23rd, 2007
Good afternoon Veena,
I am getting Run-time error 424 - Object required on this line ==>:"lvw.ListItems.Add , , OutlookAddressEntry.Name"


See my code below:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Set OutlookApp = New Outlook.Application
  2. Set OutlookMailItem = OutlookApp.CreateItem(0)
  3. Set OutlookNSpace = OutlookApp.GetNamespace("MAPI")
  4.  
  5. For Each OutlookAddressList In OutlookNSpace.AddressLists
  6. For Each OutlookAddressEntry In OutlookAddressList.AddressEntries
  7. lvw.ListItems.Add , , OutlookAddressEntry.Name
  8. lvw.ListItems(lvw.ListItems.Count).SubItems(1) = OutlookAddressEntry.Address
  9. lvw.ListItems(lvw.ListItems.Count).SubItems(2) = OutlookAddressEntry.ID
  10. lvw.ListItems(lvw.ListItems.Count).Tag = OutlookAddressEntry.ID
  11. Next
  12. Next
  13.  
  14. EmailID = lvw.ListItems(lvw.ListItems.Count).SubItems(1)
  15.  
  16. OutlookMailItem.To = EmailID
  17. OutlookMailItem.Subject = "Project Status"
  18. OutlookMailItem.Body = "This is VB email test"
  19.  
  20. If Len(MailAttach) > 0 Then
  21. OutlookMailItem.Attachments.Add "C:\ProjectStatus.xls", olByValue, 1, "ProjectStatus"
  22. End If
  23.  
  24. 'OutlookMailItem.Display 'To display the email
  25. OutlookMailItem.Send 'To send the email

Thanks
tgifgemini
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: VB6 - Look up email address from outlook address book?

 
0
  #7
Jul 24th, 2007
Hi tgif,

Just remove the Listview, and add a MSFlexgrid, rename it as grd. check this code:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub FillListView()
  2. Dim olApp As Outlook.Application
  3. Dim olNS As Outlook.NameSpace
  4. Dim olAL As Outlook.AddressList
  5. Dim olAE As Outlook.AddressEntry
  6. Dim olMail As Outlook.MailItem
  7. Dim i As Long
  8. Grd.Rows=1
  9. Grd.Cols=4
  10. i=0
  11. Set olApp = New Outlook.Application
  12. Set olNS = olApp.GetNamespace("MAPI")
  13. For Each olAL In olNS.AddressLists
  14. For Each olAE In olAL.AddressEntries
  15. i=i+1
  16. Grd.rows=i+1
  17. Grd.textMatrix(i,0)=olAE.Name
  18. Grd.textMatrix(i,1)=olAE.Address
  19. Grd.textMatrix(i,2)=olAE.ID
  20. Grd.textMatrix(i,3)=olAE.ID
  21. Next
  22. Next
  23. End Sub

Regards
Veena
Last edited by QVeen72; Jul 24th, 2007 at 3:25 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 113
Reputation: tgifgemini is an unknown quantity at this point 
Solved Threads: 0
tgifgemini tgifgemini is offline Offline
Junior Poster

Re: VB6 - Look up email address from outlook address book?

 
0
  #8
Jul 24th, 2007
Good morning Veena,
Your directives is getting me closer to my objective. I did as you said. Now, I am stepping thru the program and I can see the email address information being loaded into the flexgrid control. However at a point, I want to be able to select an email address from the flexgrid, place it in the "EmailID" variable which I will subsequently point to in the "OutlookMailItem.To = EmailID"

See all my code/setup below:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Flxgrd_Click()
  2. Dim OutlookApp As Outlook.Application
  3. Dim OutlookNameSpace As Outlook.NameSpace
  4. Dim OutlookAddressList As Outlook.AddressList
  5. Dim OutlookAddressEntry As Outlook.AddressEntry
  6. Dim OutlookMailItem As Outlook.MailItem
  7. Dim i As Long
  8. Dim EmailID As String
  9. Dim OutlookAttachment As Outlook.Attachment
  10. Dim MailAttach As String
  11.  
  12. MailAttach = "C:\ProjectStatus.xls"
  13.  
  14. Flxgrd.Rows = 1
  15. Flxgrd.Cols = 4
  16. i = 0
  17.  
  18. Set OutlookApp = New Outlook.Application
  19. Set OutlookNameSpace = OutlookApp.GetNamespace("MAPI")
  20.  
  21.  
  22. For Each OutlookAddressList In OutlookNameSpace.AddressLists
  23. For Each OutlookAddressEntry In OutlookAddressList.AddressEntries
  24. i = i + 1
  25. Flxgrd.Rows = i + 1
  26. Flxgrd.TextMatrix(i, 0) = OutlookAddressEntry.Name
  27. Flxgrd.TextMatrix(i, 1) = OutlookAddressEntry.Address
  28. Flxgrd.TextMatrix(i, 2) = OutlookAddressEntry.ID
  29. Flxgrd.TextMatrix(i, 3) = OutlookAddressEntry.ID
  30. Next
  31. Next
  32.  
  33. EmailID = "gift.xtian@nyct.com"
  34.  
  35. SENDEMAIL:
  36. OutlookMailItem.To = EmailID
  37. OutlookMailItem.Subject = "Project Status"
  38. OutlookMailItem.Body = "This is VB email test"
  39.  
  40. If Not IsMissing(MailAttach) Then
  41. Set OutlookAttachment = OutlookMailItem.Attachments.Add(MailAttach)
  42. End If
  43.  
  44. 'If Len(MailAttach) > 0 Then
  45. ' OutlookMailItem.Attachments.Add "C:\ProjectStatus.xls", olByValue, 1, "ProjectStatus"
  46. 'End If
  47.  
  48. 'OutlookMailItem.Display 'To display the email
  49. OutlookMailItem.Send 'To send the email
  50.  
  51. Set OutlookApp = Nothing
  52. Set OutlookMailItem = Nothing
  53. Set OutlookNameSpace = Nothing
  54. Set OutlookAddressList = Nothing
  55. Set OutlookAddressEntry = Nothing
  56. Set OutlookAttachment = Nothing
  57. End Sub
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 113
Reputation: tgifgemini is an unknown quantity at this point 
Solved Threads: 0
tgifgemini tgifgemini is offline Offline
Junior Poster

Re: VB6 - Look up email address from outlook address book?

 
0
  #9
Jul 25th, 2007
Good morning all:
Did anyone give a crack at my problem in my last post?
Thanks.
tgifgemini.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 113
Reputation: tgifgemini is an unknown quantity at this point 
Solved Threads: 0
tgifgemini tgifgemini is offline Offline
Junior Poster

Re: VB6 Runtime Error: 380 Invalid property value (Accessing global email address fld

 
0
  #10
Jul 25th, 2007
Hi Veena,
Sorry I've been going back and forth with this issue. But I was able to bring in the "ListView" control component and my code is executing up to a point where I get a "Runtime error - 380 - Invalid Property value" on these lines of codes:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. lvw.ListItems(lvw.ListItems.Count).SubItems(1) = OutlookAddressEntry.Address
  2. lvw.ListItems(lvw.ListItems.Count).SubItems(2) = OutlookAddressEntry.ID
  3. lvw.ListItems(lvw.ListItems.Count).Tag = OutlookAddressEntry.ID

Also, I want to be able to select my desired email address from the list.


Below is my entire code:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim OutlookApp As Outlook.Application
  2. Dim OutlookNameSpace As Outlook.NameSpace
  3. Dim OutlookAddressList As Outlook.AddressList
  4. Dim OutlookAddressEntry As Outlook.AddressEntry
  5. Dim OutlookMailItem As Outlook.MailItem
  6. Dim i As Long
  7. Dim EmailID As String
  8. Dim OutlookAttachment As Outlook.Attachment
  9. Dim MailAttach As String
  10.  
  11.  
  12.  
  13. MailAttach = "C:\ProjectStatus.xls"
  14.  
  15.  
  16. Set OutlookApp = New Outlook.Application
  17. Set OutlookMailItem = OutlookApp.CreateItem(olMailItem)
  18. Set OutlookNameSpace = OutlookApp.GetNamespace("MAPI")
  19.  
  20. For Each OutlookAddressList In OutlookNameSpace.AddressLists
  21. For Each OutlookAddressEntry In OutlookAddressList.AddressEntries
  22. lvw.ListItems.Add , , OutlookAddressEntry.Name
  23. lvw.ListItems(lvw.ListItems.Count).SubItems(1) = OutlookAddressEntry.Address
  24. lvw.ListItems(lvw.ListItems.Count).SubItems(2) = OutlookAddressEntry.ID
  25. lvw.ListItems(lvw.ListItems.Count).Tag = OutlookAddressEntry.ID
  26. Next
  27. Next
  28.  
  29. EmailID = "????????????????????????"
  30.  
  31. OutlookMailItem.To = EmailID
  32. OutlookMailItem.Subject = "Project Status"
  33. OutlookMailItem.Body = "This is VB email test"
  34.  
  35. If Len(MailAttach) > 0 Then
  36. OutlookMailItem.Attachments.Add (MailAttach)
  37. End If
  38.  
  39. 'OutlookMailItem.Display 'To display the email
  40. OutlookMailItem.Send 'To send the email
  41. End Sub
Thanks,
tgifgemini.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC