PC Review


Reply
Thread Tools Rate Thread

Redemption Data Object - How do you get a static list of message items in the Inbox for looping?

 
 
Janina
Guest
Posts: n/a
 
      8th Dec 2005
Hello,

I am using Redemption Data Objects to read messages in the Inbox
folder. This is being run as a Windows scheduled script so I do not
want the process to run indefinitely. The problem I am having is I
can't seem to take a snapshot of the email messages in the Inbox when
the script first starts. I need to loop through each message, save to
a SQL database, then delete the message from the Inbox. My index
becomes incorrect if a "New" message is sent to the Inbox during
processing and some messages get skipped over. Is there any way around
this? My index remains correct when I delete a message since I start
with the last message first (nEmailCount).

Here is my code below:

' Create RDO Session
Set Session = CreateObject("Redemption.RDOSession")
'Session.Logon 'logs on to default Outlook Profile if Profile Name is
not specified
Set Application = CreateObject("Outlook.Application")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT

' Open default Inbox folder
olFolderInbox = 6
Set Inbox = Session.GetDefaultFolder(olFolderInbox)
Set oItems = Inbox.Items

' Count email messages in folder
nEmailCount = oItems.Count
f_log "Total Email Count [" & nEmailCount & "]"
If nEmailCount = -1 Then
objShell.LogEvent information, "Error with Inbox.Items.Count
method"
f_error "Error with Inbox.Items.Count method"
End If

' Process each message in the Inbox
For i = nEmailCount To 1 Step -1
f_log "Processing Email # [" & i & "]"
Set oMsg = oItems.Item(i)
f_log "Contents of oMsg [" & oMsg & "]"

If IsNull(oMsg) Or IsEmpty(oMsg) Then
objShell.LogEvent information, "Error with Retrieve method"
f_log "Error with Retrieve method"
Exit For
End If

' Subject
sSubject = oMsg.Subject
f_log "Subject [" & sSubject & "]"

' From
sFrom = oMsg.SenderName

' Message ID
messageID = oMsg.EntryId
f_log "Message ID [" & messageID & "]"

' Retrieve To and CC Recipients
Set oRecipients = oMsg.Recipients
nRecipientCount = oRecipients.Count
f_log "Total Recipient Count [" & nRecipientCount & "]"

sTo = ""
sCC = ""
For j = 1 To nRecipientCount
Set oRecipient = oRecipients.Item(j)

' Check Recipient Type
If oRecipient.Type = 1 Then ' To
nToCount = nToCount + 1
If j = 1 Then
contactId = ""
leadId = ""
contactId = contactLookupXML(oRecipient.Address)
If contactId = "" Then contactId = "0000000000000000"
leadId = leadLookupXML(oRecipient.Address)
If leadId = "" Then leadId = "0000000000000000"
End If
If InStr(1, sTo, oRecipient.Address) > 0 Then
' do not add
Else
' add recipient
If Len(sTo) = 0 Then
sTo = oRecipient.Address
Else
sTo = sTo & "; " & oRecipient.Address
End If
End If
ElseIf oRecipient.Type = 2 Then ' CC
nCCCount = nCCCount + 1
If InStr(1, sCC, oRecipient.Address) > 0 Then
' do not add
Else
' add recipient
If Len(sCC) = 0 Then
sCC = oRecipient.Address
Else
sCC = sCC & "; " & oRecipient.Address
End If
End If
Else 'BCC
' do nothing
End If
Next

If sTo = "" Then
f_log "No TO found in this email!" & sSubject
End If
f_log "To Count [" & nToCount & "] To [" & sTo & "]"
f_log "CC Count [" & nCCCount & "] CC [" & sCC & "]"

f_log "BodyFormat [" & oMsg.BodyFormat & "]"
Select Case oMsg.BodyFormat
Case 0:
' unspecified
sBody = Trim(oMsg.Body) '?
Case 1:
' plain text
sBody = Trim(oMsg.Body)
Case 2:
' html
sBody = Trim(oMsg.HTMLBody)
Case 3:
' rich text
sBody = Trim(oMsg.RTFBody)
End Select

If contactId <> "0000000000000000" Or leadId <> "0000000000000000"
Then
' Save the email message to the file system
sFilePath = "C:\msg\"
sFileName = messageID & ".msg"
oMsg.SaveAs sFilePath & sFileName

If createActivity = 1 And createInteraction(sFrom, sTo, sCC,
sSubject, sBody, contactId, messageID) = 1 Then
' Delete from Inbox
oMsg.Delete
End If
Else
f_log "Skipping this email."
End If
Next
f_log "END [" & Date & " " & Time & "]"

Thanks,
Janina

 
Reply With Quote
 
 
 
 
Dmitry Streblechenko
Guest
Posts: n/a
 
      8th Dec 2005
Try to use "for each" loop instead.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Janina" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I am using Redemption Data Objects to read messages in the Inbox
> folder. This is being run as a Windows scheduled script so I do not
> want the process to run indefinitely. The problem I am having is I
> can't seem to take a snapshot of the email messages in the Inbox when
> the script first starts. I need to loop through each message, save to
> a SQL database, then delete the message from the Inbox. My index
> becomes incorrect if a "New" message is sent to the Inbox during
> processing and some messages get skipped over. Is there any way around
> this? My index remains correct when I delete a message since I start
> with the last message first (nEmailCount).
>
> Here is my code below:
>
> ' Create RDO Session
> Set Session = CreateObject("Redemption.RDOSession")
> 'Session.Logon 'logs on to default Outlook Profile if Profile Name is
> not specified
> Set Application = CreateObject("Outlook.Application")
> Session.MAPIOBJECT = Application.Session.MAPIOBJECT
>
> ' Open default Inbox folder
> olFolderInbox = 6
> Set Inbox = Session.GetDefaultFolder(olFolderInbox)
> Set oItems = Inbox.Items
>
> ' Count email messages in folder
> nEmailCount = oItems.Count
> f_log "Total Email Count [" & nEmailCount & "]"
> If nEmailCount = -1 Then
> objShell.LogEvent information, "Error with Inbox.Items.Count
> method"
> f_error "Error with Inbox.Items.Count method"
> End If
>
> ' Process each message in the Inbox
> For i = nEmailCount To 1 Step -1
> f_log "Processing Email # [" & i & "]"
> Set oMsg = oItems.Item(i)
> f_log "Contents of oMsg [" & oMsg & "]"
>
> If IsNull(oMsg) Or IsEmpty(oMsg) Then
> objShell.LogEvent information, "Error with Retrieve method"
> f_log "Error with Retrieve method"
> Exit For
> End If
>
> ' Subject
> sSubject = oMsg.Subject
> f_log "Subject [" & sSubject & "]"
>
> ' From
> sFrom = oMsg.SenderName
>
> ' Message ID
> messageID = oMsg.EntryId
> f_log "Message ID [" & messageID & "]"
>
> ' Retrieve To and CC Recipients
> Set oRecipients = oMsg.Recipients
> nRecipientCount = oRecipients.Count
> f_log "Total Recipient Count [" & nRecipientCount & "]"
>
> sTo = ""
> sCC = ""
> For j = 1 To nRecipientCount
> Set oRecipient = oRecipients.Item(j)
>
> ' Check Recipient Type
> If oRecipient.Type = 1 Then ' To
> nToCount = nToCount + 1
> If j = 1 Then
> contactId = ""
> leadId = ""
> contactId = contactLookupXML(oRecipient.Address)
> If contactId = "" Then contactId = "0000000000000000"
> leadId = leadLookupXML(oRecipient.Address)
> If leadId = "" Then leadId = "0000000000000000"
> End If
> If InStr(1, sTo, oRecipient.Address) > 0 Then
> ' do not add
> Else
> ' add recipient
> If Len(sTo) = 0 Then
> sTo = oRecipient.Address
> Else
> sTo = sTo & "; " & oRecipient.Address
> End If
> End If
> ElseIf oRecipient.Type = 2 Then ' CC
> nCCCount = nCCCount + 1
> If InStr(1, sCC, oRecipient.Address) > 0 Then
> ' do not add
> Else
> ' add recipient
> If Len(sCC) = 0 Then
> sCC = oRecipient.Address
> Else
> sCC = sCC & "; " & oRecipient.Address
> End If
> End If
> Else 'BCC
> ' do nothing
> End If
> Next
>
> If sTo = "" Then
> f_log "No TO found in this email!" & sSubject
> End If
> f_log "To Count [" & nToCount & "] To [" & sTo & "]"
> f_log "CC Count [" & nCCCount & "] CC [" & sCC & "]"
>
> f_log "BodyFormat [" & oMsg.BodyFormat & "]"
> Select Case oMsg.BodyFormat
> Case 0:
> ' unspecified
> sBody = Trim(oMsg.Body) '?
> Case 1:
> ' plain text
> sBody = Trim(oMsg.Body)
> Case 2:
> ' html
> sBody = Trim(oMsg.HTMLBody)
> Case 3:
> ' rich text
> sBody = Trim(oMsg.RTFBody)
> End Select
>
> If contactId <> "0000000000000000" Or leadId <> "0000000000000000"
> Then
> ' Save the email message to the file system
> sFilePath = "C:\msg\"
> sFileName = messageID & ".msg"
> oMsg.SaveAs sFilePath & sFileName
>
> If createActivity = 1 And createInteraction(sFrom, sTo, sCC,
> sSubject, sBody, contactId, messageID) = 1 Then
> ' Delete from Inbox
> oMsg.Delete
> End If
> Else
> f_log "Skipping this email."
> End If
> Next
> f_log "END [" & Date & " " & Time & "]"
>
> Thanks,
> Janina
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"An object reference is required for the non-static field, method, orproperty" compilation error generated from non-static context dejas9000@gmail.com Microsoft C# .NET 7 26th Jan 2008 01:02 PM
Useing Redemption Object to Read an Inbox Damian Microsoft Outlook Program Addins 9 8th Jun 2006 06:57 AM
How to get MailItem Subject using Redemption::ISafeMailItem object Kavita Joshi via OfficeKB.com Microsoft Outlook Program Addins 3 30th Jun 2005 06:13 PM
Sent redemption message not added to Sent Items folder Jack Microsoft Outlook VBA Programming 3 22nd Apr 2005 03:08 PM
Static class method return non-static object? Paschalis Pagonidis Microsoft C# .NET 8 10th Nov 2004 11:10 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:15 AM.