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.

SENDEMAIL:
 Set OutlookApp = CreateObject("Outlook.Application")
 Set OutlookMail = OutlookApp.CreateItem(0)
 
 OutlookMail.To = EmailID
 OutlookMail.Subject = "Project Status"
 OutlookMail.Body = "This is VB email test"
 
 If Len(MailAttach) = 0 Then
    OutlookMail.Attachments.Add MailAttach  '"C:\ProjectStatus.xls"
 End If

tgifgemini

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.

SENDEMAIL:
 Set OutlookApp = CreateObject("Outlook.Application")
 Set OutlookMail = OutlookApp.CreateItem(0)
 
 OutlookMail.To = EmailID
 OutlookMail.Subject = "Project Status"
 OutlookMail.Body = "This is VB email test"
 
 If Len(MailAttach) = 0 Then
    OutlookMail.Attachments.Add MailAttach  '"C:\ProjectStatus.xls"
 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

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

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!

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:

Private Sub FillListView()

Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olAL As Outlook.AddressList
Dim olAE As Outlook.AddressEntry
Dim olMail As Outlook.MailItem

    Set olApp = New Outlook.Application
    Set olNS = olApp.GetNamespace("MAPI")
    For Each olAL In olNS.AddressLists
        For Each olAE In olAL.AddressEntries
            lvw.ListItems.Add , , olAE.Name
            lvw.ListItems(lvw.ListItems.Count).SubItems(1) = olAE.Address
            lvw.ListItems(lvw.ListItems.Count).SubItems(2) = olAE.ID
            lvw.ListItems(lvw.ListItems.Count).Tag = olAE.ID
        Next
    Next
End Sub

REgards
Veena

Good afternoon Veena,
I am getting Run-time error 424 - Object required on this line ==>:"lvw.ListItems.Add , , OutlookAddressEntry.Name"


See my code below:

Set OutlookApp = New Outlook.Application
 Set OutlookMailItem = OutlookApp.CreateItem(0)
 Set OutlookNSpace = OutlookApp.GetNamespace("MAPI")
 
For Each OutlookAddressList In OutlookNSpace.AddressLists
    For Each OutlookAddressEntry In OutlookAddressList.AddressEntries
        lvw.ListItems.Add , , OutlookAddressEntry.Name
        lvw.ListItems(lvw.ListItems.Count).SubItems(1) = OutlookAddressEntry.Address
        lvw.ListItems(lvw.ListItems.Count).SubItems(2) = OutlookAddressEntry.ID
        lvw.ListItems(lvw.ListItems.Count).Tag = OutlookAddressEntry.ID
    Next
Next

EmailID = lvw.ListItems(lvw.ListItems.Count).SubItems(1)
 
 OutlookMailItem.To = EmailID
 OutlookMailItem.Subject = "Project Status"
 OutlookMailItem.Body = "This is VB email test"
 
 If Len(MailAttach) > 0 Then
    OutlookMailItem.Attachments.Add "C:\ProjectStatus.xls", olByValue, 1, "ProjectStatus"
 End If
 
 'OutlookMailItem.Display      'To display the email
 OutlookMailItem.Send         'To send the email

Thanks
tgifgemini

Hi tgif,

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

Private Sub FillListView()
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olAL As Outlook.AddressList
Dim olAE As Outlook.AddressEntry
Dim olMail As Outlook.MailItem
Dim i As Long
Grd.Rows=1
Grd.Cols=4
i=0    
Set olApp = New Outlook.Application   
Set olNS = olApp.GetNamespace("MAPI")  
For Each olAL In olNS.AddressLists  
      For Each olAE In olAL.AddressEntries
          i=i+1
         Grd.rows=i+1     
         Grd.textMatrix(i,0)=olAE.Name
         Grd.textMatrix(i,1)=olAE.Address
         Grd.textMatrix(i,2)=olAE.ID
         Grd.textMatrix(i,3)=olAE.ID        
   Next    
Next
End Sub

Regards
Veena

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:

Private Sub Flxgrd_Click()
Dim OutlookApp As Outlook.Application
Dim OutlookNameSpace As Outlook.NameSpace
Dim OutlookAddressList As Outlook.AddressList
Dim OutlookAddressEntry As Outlook.AddressEntry
Dim OutlookMailItem As Outlook.MailItem
Dim i As Long
Dim EmailID As String
Dim OutlookAttachment As Outlook.Attachment
Dim MailAttach As String

MailAttach = "C:\ProjectStatus.xls"

Flxgrd.Rows = 1
Flxgrd.Cols = 4
i = 0

Set OutlookApp = New Outlook.Application
Set OutlookNameSpace = OutlookApp.GetNamespace("MAPI")


For Each OutlookAddressList In OutlookNameSpace.AddressLists
      For Each OutlookAddressEntry In OutlookAddressList.AddressEntries
          i = i + 1
         Flxgrd.Rows = i + 1
         Flxgrd.TextMatrix(i, 0) = OutlookAddressEntry.Name
         Flxgrd.TextMatrix(i, 1) = OutlookAddressEntry.Address
         Flxgrd.TextMatrix(i, 2) = OutlookAddressEntry.ID
         Flxgrd.TextMatrix(i, 3) = OutlookAddressEntry.ID
   Next
Next

EmailID = "gift.xtian@nyct.com"

SENDEMAIL:
 OutlookMailItem.To = EmailID
 OutlookMailItem.Subject = "Project Status"
 OutlookMailItem.Body = "This is VB email test"
 
 If Not IsMissing(MailAttach) Then
    Set OutlookAttachment = OutlookMailItem.Attachments.Add(MailAttach)
 End If
 
 'If Len(MailAttach) > 0 Then
 '   OutlookMailItem.Attachments.Add "C:\ProjectStatus.xls", olByValue, 1, "ProjectStatus"
 'End If
 
 'OutlookMailItem.Display      'To display the email
 OutlookMailItem.Send         'To send the email
    
 Set OutlookApp = Nothing
 Set OutlookMailItem = Nothing
 Set OutlookNameSpace = Nothing
 Set OutlookAddressList = Nothing
 Set OutlookAddressEntry = Nothing
 Set OutlookAttachment = Nothing
End Sub

Good morning all:
Did anyone give a crack at my problem in my last post?
Thanks.
tgifgemini.

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:

lvw.ListItems(lvw.ListItems.Count).SubItems(1) = OutlookAddressEntry.Address
        lvw.ListItems(lvw.ListItems.Count).SubItems(2) = OutlookAddressEntry.ID
        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:

Dim OutlookApp As Outlook.Application
Dim OutlookNameSpace As Outlook.NameSpace
Dim OutlookAddressList As Outlook.AddressList
Dim OutlookAddressEntry As Outlook.AddressEntry
Dim OutlookMailItem As Outlook.MailItem
Dim i As Long
Dim EmailID As String
Dim OutlookAttachment As Outlook.Attachment
Dim MailAttach As String



MailAttach = "C:\ProjectStatus.xls"


Set OutlookApp = New Outlook.Application
Set OutlookMailItem = OutlookApp.CreateItem(olMailItem)
Set OutlookNameSpace = OutlookApp.GetNamespace("MAPI")
 
For Each OutlookAddressList In OutlookNameSpace.AddressLists
    For Each OutlookAddressEntry In OutlookAddressList.AddressEntries
        lvw.ListItems.Add , , OutlookAddressEntry.Name
        lvw.ListItems(lvw.ListItems.Count).SubItems(1) = OutlookAddressEntry.Address
        lvw.ListItems(lvw.ListItems.Count).SubItems(2) = OutlookAddressEntry.ID
        lvw.ListItems(lvw.ListItems.Count).Tag = OutlookAddressEntry.ID
    Next
Next

EmailID = "????????????????????????"
 
 OutlookMailItem.To = EmailID
 OutlookMailItem.Subject = "Project Status"
 OutlookMailItem.Body = "This is VB email test"
 
 If Len(MailAttach) > 0 Then
    OutlookMailItem.Attachments.Add (MailAttach)
 End If
 
 'OutlookMailItem.Display      'To display the email
 OutlookMailItem.Send         'To send the email
End Sub

Thanks,
tgifgemini.

Hi tgif,

use this code:

Dim TItem As ListItem
If lvw.SelectedItem.text <> "" Then
  Set TItem = lvw.SelectedItem
  EMailID=TItem.SubItems(2)
Else
  MsgBox "No Item Selected From list"
End If

Regards
Veena

Good morning Veena.
Thanks for your numerous contributions. I put the codes below inside my form load() module, because I want the listview control to get populated on form load then I can select and email from the list then click the sendEmail button.
However, when I tried to compile, I get Error msg: Run-Time error 380 -Invalid property value:

This line of code generates the error:

lvw.ListItems(lvw.ListItems.Count).SubItems(1) = OutlookAddressEntry.Address

Below is my form load module:

Private Sub Form_Load()

Set OutlookApp = New Outlook.Application
Set OutlookMailItem = OutlookApp.CreateItem(olMailItem)
Set OutlookNameSpace = OutlookApp.GetNamespace("MAPI")


For Each OutlookAddressList In OutlookNameSpace.AddressLists
    For Each OutlookAddressEntry In OutlookAddressList.AddressEntries
        lvw.ListItems.Add , , OutlookAddressEntry.Name
        lvw.ListItems(lvw.ListItems.Count).SubItems(1) = OutlookAddressEntry.Address
        lvw.ListItems(lvw.ListItems.Count).SubItems(2) = OutlookAddressEntry.ID
        lvw.ListItems(lvw.ListItems.Count).Tag = OutlookAddressEntry.ID
    Next
Next
End Sub

Thanks,
tgifgemini

Hi,

Just change the code:
Set lvw.ReportType = lvwReport

Dim X As ListItem

Set OutlookApp = New Outlook.Application
Set OutlookMailItem = OutlookApp.CreateItem(olMailItem)
Set OutlookNameSpace = OutlookApp.GetNamespace("MAPI")


For Each OutlookAddressList In OutlookNameSpace.AddressLists
    For Each OutlookAddressEntry In OutlookAddressList.AddressEntries
       set X= lvw.ListItems.Add( , , OutlookAddressEntry.Name)
        X.SubItems(1) = OutlookAddressEntry.Address
        X.SubItems(2) = OutlookAddressEntry.ID
        X.Tag = OutlookAddressEntry.ID
    Next
Next

Regards
Veena

Good morning Veena,
how are you doing today? I really do appreciate all your assistance. I plugged in recent code you you gave me and I am getting same "RunTime error 380 - Invalid property value". I am going nuts with this Microsoft stuff that is not telling you what the actual problem is.
And I don't know where else to look.

Thanks.
tgifgemini

Good morning Veena,
how are you doing today? I really do appreciate all your assistance. I plugged in recent code you you gave me and I am getting same "RunTime error 380 - Invalid property value" on this line of code: x.subItems(1) = OutlookAddressEntry.Address and a compile error: "Method or Data member not found" on this line: Set lvw.ReportType = lvwReport I am going nuts with this Microsoft stuff that is not telling you what the actual problem is.
And I don't know where else to look.

Question: Shouldn't I first Dimension "lvw" as something before the 'set lvw.ReportType = lvwReport' statement?

Thanks.
tgifgemini

Veena,
Actually, I went ahead and created ListView header columns which I didn't have initially, therefore since I want to display 3 items in the columns, it didn't find any columns to append the items.

This is what I did:

'create columns
lvw.ColumnHeaders.Clear
lvw.ColumnHeaders.Add , ,"Address"
lvw.ColumnHeaders.Add , ,"ID"

And it populated the ListView with the the physical names "gift, xtian" etc.
So I used the first subscript(1) as the address and it worked like magic.
Thanks.
You're a true trooper for holding my hand all along.
tgifgemini.

Hi,

OK, its:

lvw.view=3

And u have to add column headers..
Write this code b4 populating the list..

Dim lvwColumn As ColumnHeader

     lvwColumn = New ColumnHeader()
     lvwColumn.Text = "Name"   
     lvw.Columns.Add(lvwColumn)
 
     lvwColumn = New ColumnHeader()
     lvwColumn.Text = "Address"   
     lvw.Columns.Add(lvwColumn)

     lvwColumn = New ColumnHeader()
     lvwColumn.Text = "ID"   
     lvw.Columns.Add(lvwColumn)

Sorry for the inconvinience..

Regards
Veena

Hello All.

You people are waisting your time and energy. And I can't understand, why people gives in this thread so many type of codes, telling one way or the other I am soory, please change to this, please omit that etc. without first understanding the basic of it or trying the code themselves! If you have heeded to my advice in this forum by telling gemini that the answer is NO as well as Yes.

I will put it briefly below. Think about it and answer me.

First of all, if you are thinking Outlook Express, just forget it. The only three ways of integrating with Outlook Express are (and this is just my guessing) by paying Microsoft a lot of money and by giving them a really good reason to why you want to do that, or by hooking in through the encryption-entry, or by creating a proper hook and hacking your way in there.

Could you make out any thing from the bold entries above?

Happy Programming

AV Manoharan


Hi AV Manoharan,
I don't know what you are babbling about, but Veena have correctly answered my question, so be cool.
tgifgemini.

Hi AV Manoharan,
I don't know what you are babbling about, but Veena have correctly answered my question, so be cool.
tgifgemini.

Correctly answered what? Getting email address from the outlook express? The email addresses stored in the outlook express are encrypted ! and you and Veena Could hack it and decrypt it. Fantastic Dear.


regards
AV Manoharan

hI MANOHAR,

IF U DONT HAVE ANY IDEA ON HOW TO GET ADDRESS LIST FROM OUTLOOK EXPRESS, WHY POKE UR NOSE INTO THIE THREAD..?..

IT IS A M$ EXAMPLE.. EVERY ONE USES IT..

If u dnot know abt it.. simply keep quite..

Vee

hI MANOHAR,

IF U DONT HAVE ANY IDEA ON HOW TO GET ADDRESS LIST FROM OUTLOOK EXPRESS, WHY POKE UR NOSE INTO THIE THREAD..?..

IT IS A M$ EXAMPLE.. EVERY ONE USES IT..

If u dnot know abt it.. simply keep quite..

Vee

Veena,
You are crossing the limit of valgarity. Many other people in this forum has expressed their grievences on your language. And beware I am going to inform Dani and the queen of Dani to open the private messege you have sent to me- if you further repeat it.

I have expressed my views. First try to understand the language. An address list and email address are two different things. And to my whole knowledge, Microsoft's outlook express stores the email ids encrypted and you cannot access it other than through the registry that too as a rescue operation for a crashed Outlook express.

If you could directly access through VB, Contact Microsoft. I think Bill will have a senior position waiting for you. Do not waist your time with us (your word).

still with regards

AV Manoharan

Hi manohar,

I dont believe u still are Hanging in this Thread...?
I wud like to know who else has complained abt my language,
as it is i have received reputaion Points for being up to the point.. and solving the problems.. In turn, many people have problem with ur Language..
I just tyold u to keep away from things which u dont know.. it dosent mean Vulgarity..

If TGIF has told his problem is solved then why u have the problem...?

u r warning me,,? Please get my pvt post to be shown in Public.. I would enjoy it..

and who u think, i'am working for...? M$ has already employed me.. so I'am safe at my "Senior Post".. so dont worry abt my Job..

Regards
Veena

Hi manohar,

I dont believe u still are Hanging in this Thread...?
I wud like to know who else has complained abt my language,
as it is i have received reputaion Points for being up to the point.. and solving the problems.. In turn, many people have problem with ur Language..
I just tyold u to keep away from things which u dont know.. it dosent mean Vulgarity..

If TGIF has told his problem is solved then why u have the problem...?

u r warning me,,? Please get my pvt post to be shown in Public.. I would enjoy it..

and who u think, i'am working for...? M$ has already employed me.. so I'am safe at my "Senior Post".. so dont worry abt my Job..

Regards
Veena

Once more you read the private messege which you have sent to me. Then you judge yourself whether it is not vulgar or not. You have a habit of answering questions without really going through it properly,

eg.
When a person asks in the forum whether it is possible to access a password protected database (without knowing the password). You are ready with the often repeated connection string with the password= mypwd. And when suneel and others asks you again and again, instead of telling sorry, you outbursted to them "I am not a hacker" and all that.

See, if you earned reputation for solving problems it is good. We appreciate you. But it doesn't guarantee you to be harsh and vulgar to people in this forum. This forum is for vide range of discussions. Not intune with your ordering to stay in the thread or not.

Try to understand. You are simply inviting trouble. Not even one sentence in my whole posting in Dani web is out of context. All those postings are for the good of the learners.

Happy programming

AV Manoharan

So,


u told Jireh to Change her Picture Profie,..?
U told debasidas That his name resonates to a DB..?
U told Jatinder_44, that whenever U open his thread u get "Jitters"..?
(when he asked solution for Comm Port, that person Marked that thread as Solved without getting real help from this Forum and u r responsible for that)
U told me not to give Solution for "OutlookExpress"

they have not complained dosent mean every one is ok with ur suggestions.. they have just Ignored it..

So u r no Moderator and dont have any rights to tell people about their personnel choices.
and I know what i have written in the pvt post to u... thats the Reason i want u to make it Public.. dosent matter if it is Vulgar for u..

So u want to know where u have gone wrong...?,


u told Jireh to Change her Picture Profie,..?
U told debasidas That his name resonates to a DB..?
U told Jatinder_44, that whenever U open his thread u get "Jitters"..?
(when he asked solution for Comm Port, that person Marked that thread as Solved without getting real help from this Forum and u r responsible for that)
U told me not to give Solution for "OutlookExpress"

they have not complained dosent mean every one is ok with ur suggestions.. they have just Ignored it..

So u r no Moderator and dont have any rights to tell people about their personnel choices.
and I know what i have written in the pvt post to u... thats the Reason i want u to make it Public.. dosent matter if it is Vulgar for u..

So u want to know where u have gone wrong...?,


u told Jireh to Change her Picture Profie,..?
U told debasidas That his name resonates to a DB..?
U told Jatinder_44, that whenever U open his thread u get "Jitters"..?
(when he asked solution for Comm Port, that person Marked that thread as Solved without getting real help from this Forum and u r responsible for that)
U told me not to give Solution for "OutlookExpress"

they have not complained dosent mean every one is ok with ur suggestions.. they have just Ignored it..

So u r no Moderator and dont have any rights to tell people about their personnel choices.
and I know what i have written in the pvt post to u... thats the Reason i want u to make it Public.. dosent matter if it is Vulgar for u..

Now the real thing is out. You are simply jelous of me.

Thank you keep it up. I take all your blames as commendation from a child not grown up to understand things.

Thank you veena
Enough

Happy Programming

AV Manoharan

Gr888..
u take whatever i tell.

i just dont want u to advice me abt ur ideas..
I wanted u to be just quite.. and u have understood it.. and if u had told this long back it wud have saved our time..

People,
let's drop this bickering and move on. No point making a mountain out of an ant hill. Veena accurately gave me her input on my microsoft email problems and it worked perfectly, so I give him/her "kudos". Let's leave it at that.
You all have a great day.
tgifgemini.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.