EntryID problem

V

vonClausowitz

Hi All,

I'm trying to compare emails in two different mailboxes. Therefor I
need the SMTP address, the only way to do that is via the EntryID.
When using my code and can't seem to get into the second mailbox. I
get an MAPI_E_LOGON failure message.

Private Sub cmdInlezen2_Click()

Dim oudDatum As Date 'datum laatst gecheckte email
Dim nieuwDatum As Date 'datum oudste email in eigen folder
Dim iNumItems, iNumOwnItems As Integer
Dim iTotal As Integer
Dim i As Integer

Dim objSession As MAPI.Session
Dim objMsg As MAPI.Message
Dim objsender As MAPI.AddressEntry
Dim objItem As outlook.MailItem

Set objSession = CreateObject("MAPI.session")
objSession.Logon "", "", False, False

iNumItems = olDeleteFolder.Items.Count
iNumOwnItems = olOwnFolder.Items.Count
iTotal = iNumItems + iNumOwnItems

'bepaal de jongste en oudste email in mijn eigen folder
oudDatum = olOwnFolder.Items.Item(iNumOwnItems).ReceivedTime 'de
oudste email
nieuwDatum = olOwnFolder.Items.Item(1).ReceivedTime 'de laatst
binnengekomen email

'eigen Inbox inlezen in Listview1
For Each olmailitem In olOwnFolder.Items
If olmailitem.Class = olMail Then 'alleen echte emails
vergelijken
If olmailitem.Subject = "" Then
GoTo NoSubject
End If
Set objMsg = objSession2.GetMessage(objItem.EntryID)
Set objsender = objMsg.Sender
Set itmX = ListView1.ListItems.Add(, ,
objsender.Address, , 2)
itmX.SubItems(1) = olmailitem.Subject
itmX.SubItems(2) = olmailitem.ReceivedTime
End If
NoSubject:
Next

'Deleted Items CLASSINT inlezen in Listview2
For Each objItem In olDeleteFolder.Items
If objItem.Class = olMail Then 'alleen echte emails vergelijken
If objItem.ReceivedTime >= oudDatum Then 'alleen emails die
jonger of even oud zijn
If objItem.Subject = "" Then
GoTo NoSubject2
End If
Set objMsg = objSession2.GetMessage(objItem.EntryID)
Set objsender = objMsg.Sender
Set itmX = ListView2.ListItems.Add(, ,
objsender.Address, , 2)
itmX.SubItems(1) = objItem.Subject
itmX.SubItems(2) = objItem.ReceivedTime
End If
If DateDiff("n", objItem.ReceivedTime, oudDatum) > 60 Then
'er moet minimaal 60 minuten tussen zitten
'If objItem.ReceivedTime < oudDatum Then 'stoppen er zijn
geen emails meer
Exit For
End If
End If
NoSubject2:
Next

End Sub

Regards
Marco
 
K

Ken Slovak - [MVP - Outlook]

That code is incomplete, I don't see where the second MAPI session is being
instantiated or how. That's the key to logging into a different mailbox,
that and the Logon.

You don't need an EntryID to log into a different mailbox using CDO 1.21.
 
V

vonClausowitz

That code is incomplete, I don't see where the second MAPI session is being
instantiated or how. That's the key to logging into a different mailbox,
that and the Logon.

You don't need an EntryID to log into a different mailbox using CDO 1.21.

--
Ken Slovak
[MVP - Outlook]http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Optionshttp://www.slovaktech.com/products.htm




I'm trying to compare emails in two different mailboxes. Therefor I
need the SMTP address, the only way to do that is via the EntryID.
When using my code and can't seem to get into the second mailbox. I
get an MAPI_E_LOGON failure message.
Private Sub cmdInlezen2_Click()
Dim oudDatum As Date 'datum laatst gecheckte email
Dim nieuwDatum As Date 'datum oudste email in eigen folder
Dim iNumItems, iNumOwnItems As Integer
Dim iTotal As Integer
Dim i As Integer
Dim objSession As MAPI.Session
Dim objMsg As MAPI.Message
Dim objsender As MAPI.AddressEntry
Dim objItem As outlook.MailItem
Set objSession = CreateObject("MAPI.session")
objSession.Logon "", "", False, False
iNumItems = olDeleteFolder.Items.Count
iNumOwnItems = olOwnFolder.Items.Count
iTotal = iNumItems + iNumOwnItems
'bepaal de jongste en oudste email in mijn eigen folder
oudDatum = olOwnFolder.Items.Item(iNumOwnItems).ReceivedTime 'de
oudste email
nieuwDatum = olOwnFolder.Items.Item(1).ReceivedTime 'de laatst
binnengekomen email
'eigen Inbox inlezen in Listview1
For Each olmailitem In olOwnFolder.Items
If olmailitem.Class = olMail Then 'alleen echte emails
vergelijken
If olmailitem.Subject = "" Then
GoTo NoSubject
End If
Set objMsg = objSession2.GetMessage(objItem.EntryID)
Set objsender = objMsg.Sender
Set itmX = ListView1.ListItems.Add(, ,
objsender.Address, , 2)
itmX.SubItems(1) = olmailitem.Subject
itmX.SubItems(2) = olmailitem.ReceivedTime
End If
NoSubject:
Next
'Deleted Items CLASSINT inlezen in Listview2
For Each objItem In olDeleteFolder.Items
If objItem.Class = olMail Then 'alleen echte emails vergelijken
If objItem.ReceivedTime >= oudDatum Then 'alleen emails die
jonger of even oud zijn
If objItem.Subject = "" Then
GoTo NoSubject2
End If
Set objMsg = objSession2.GetMessage(objItem.EntryID)
Set objsender = objMsg.Sender
Set itmX = ListView2.ListItems.Add(, ,
objsender.Address, , 2)
itmX.SubItems(1) = objItem.Subject
itmX.SubItems(2) = objItem.ReceivedTime
End If
If DateDiff("n", objItem.ReceivedTime, oudDatum) > 60 Then
'er moet minimaal 60 minuten tussen zitten
'If objItem.ReceivedTime < oudDatum Then 'stoppen er zijn
geen emails meer
Exit For
End If
End If
NoSubject2:
Next
Regards
Marco- Tekst uit oorspronkelijk bericht niet weergeven -

- Tekst uit oorspronkelijk bericht weergeven -

Ken,

What am I missing then?
This is what I had before but didn't work:

strProfile = "ServerName" & vbCrlf & "MailAccount"
Set objSession2 = CreateObject("MAPI.session")
objSession2.Logon "", "", False, True,0,False,strProfile

Someone told me that you can't access two mailboxes wit CDO.

please some example.

Marco
 
K

Ken Slovak - [MVP - Outlook]

You have to log off the first mailbox before you log into a second mailbox
in CDO.

Why are you using CDO for this anyway? I'd be using either the Outlook
object model and GetSharedDefaultFolder or Redemption. CDO is old, passe and
not standard any more. It's not supported for managed code and is being
deprecated. It's not the way to go.

Just use GetSharedDefaultFolder with a Recipient object that you create for
whoever's mailbox you want to access.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top