wwstudioinc
asked on
Need Help with outlook redemption
I have put together this code to check unread emails using redemptiom.Everything works fine I just need to restrict the messages to unread=true but i am having a problem.I need the experts.
Public Sub TestRedemption()
Dim oSession As New Redemption.rdoSession
Dim objFolder As Redemption.RDOFolder
Dim oItems As Object
Dim oItem As Redemption.RDOMail
Dim att_Ment As Object
Dim sMessageBody As String
Dim sSubject As String
Dim sPriority As Integer
oSession.Logon , , , False, False
Set objFolder = oSession.GetDefaultFolder( rdoDefault Folders.ol FolderInbo x)
' Set oItems = objFolder.Items.Restrict(" [UnRead] =true")<<<< having trouble with this line
Set oItems = objFolder.Items
For Each oItem In oItems
If (oItem.Unread) Then
sMessageBody = oItem.Body
sSubject = "From:" & oItem.Sender & vbCrLf & "To:" & oItem.To & vbCrLf & "Subject:" & oItem.Subject
sPriority = oItem.Importance
'oItem.MarkRead(True)
'oItem.Move()
If oItem.Attachments.Count > 0 Then
Set att_Ment = oItem.Attachments.item(1)
End If
Else
End If
Next
oSession = Nothing
If Not IsNothing(oSession) Then
If oSession.LoggedOn Then
oSession.Logoff
End If
End If
End Sub
thanks
Public Sub TestRedemption()
Dim oSession As New Redemption.rdoSession
Dim objFolder As Redemption.RDOFolder
Dim oItems As Object
Dim oItem As Redemption.RDOMail
Dim att_Ment As Object
Dim sMessageBody As String
Dim sSubject As String
Dim sPriority As Integer
oSession.Logon , , , False, False
Set objFolder = oSession.GetDefaultFolder(
' Set oItems = objFolder.Items.Restrict("
Set oItems = objFolder.Items
For Each oItem In oItems
If (oItem.Unread) Then
sMessageBody = oItem.Body
sSubject = "From:" & oItem.Sender & vbCrLf & "To:" & oItem.To & vbCrLf & "Subject:" & oItem.Subject
sPriority = oItem.Importance
'oItem.MarkRead(True)
'oItem.Move()
If oItem.Attachments.Count > 0 Then
Set att_Ment = oItem.Attachments.item(1)
End If
Else
End If
Next
oSession = Nothing
If Not IsNothing(oSession) Then
If oSession.LoggedOn Then
oSession.Logoff
End If
End If
End Sub
thanks
Hi wwstudioinc,
You have probably already done this but try changing
If (oItem.Unread) Then
To
If oItem.Unread = True Then
Hope this helps,
Mark.
You have probably already done this but try changing
If (oItem.Unread) Then
To
If oItem.Unread = True Then
Hope this helps,
Mark.
ASKER
mark i have that line already,the problem is that i don't want to have to be going through the entire mailbox to check for the unread items if the mailbox is large in size then that can take some time.and angel Set oItems = objFolder.Items.Restrict(" [UnRead] =true") if gives an error
you might want to "search" for the unread emails:
http://www.dimastr.com/redemption/rdo/RDOSearchFolder.htm
the restriction you want to search for:
http://www.dimastr.com/redemption/mapitable.htm#tablefiltering
hope this helps...
http://www.dimastr.com/redemption/rdo/RDOSearchFolder.htm
the restriction you want to search for:
http://www.dimastr.com/redemption/mapitable.htm#tablefiltering
hope this helps...
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
kevin i am getting the same error
I tried the above code as-is with unread items, no unread items, and no items at all and the code works every time. I tested with Outlook 2007 and Redemption 4.5.
What is the exact error?
Kevin
What is the exact error?
Kevin
ASKER
kevin you are right i had to update my redemption dll 4.4 to 4.5.Could i specify what inbox eg MSN or Hotmail instead of the default inbox
You can specific any folder you want. Here is a help routine that returns the folder object given a folder expressed as a variant array (each element of the array represents a sub-folder inside the previous folder):
Set OutlookFolderObject = GetOutlookFolder(Array("In box", "MSN"))
[Begin Code Segment]
Public Function GetOutlookFolder( _
ByVal FolderPath As Variant _
) As Outlook.Folder
Dim OutlookApplication As Outlook.Application
Dim OutlookNamespace As Outlook.Namespace
Dim OutlookFolders As Outlook.Folders
Dim OutlookFolder As Outlook.Folder
Dim Index As Long
If Not IsArray(FolderPath) Then
If Len(FolderPath) = 0 Then Exit Function
FolderPath = Array(FolderPath)
End If
Set OutlookApplication = CreateObject("Outlook.Appl ication")
Set OutlookNamespace = OutlookApplication.GetName space("MAP I")
On Error Resume Next
Set OutlookFolder = OutlookNamespace.Folders(F olderPath( LBound(Fol derPath)))
If OutlookFolder Is Nothing Then Exit Function
For Index = LBound(FolderPath) + 1 To UBound(FolderPath)
Set OutlookFolder = OutlookFolder.Folders(Fold erPath(Ind ex))
If OutlookFolder Is Nothing Then Exit Function
Next Index
On Error GoTo 0
Set GetOutlookFolder = OutlookFolder
End Function
[End Code Segment]
Kevin
Set OutlookFolderObject = GetOutlookFolder(Array("In
[Begin Code Segment]
Public Function GetOutlookFolder( _
ByVal FolderPath As Variant _
) As Outlook.Folder
Dim OutlookApplication As Outlook.Application
Dim OutlookNamespace As Outlook.Namespace
Dim OutlookFolders As Outlook.Folders
Dim OutlookFolder As Outlook.Folder
Dim Index As Long
If Not IsArray(FolderPath) Then
If Len(FolderPath) = 0 Then Exit Function
FolderPath = Array(FolderPath)
End If
Set OutlookApplication = CreateObject("Outlook.Appl
Set OutlookNamespace = OutlookApplication.GetName
On Error Resume Next
Set OutlookFolder = OutlookNamespace.Folders(F
If OutlookFolder Is Nothing Then Exit Function
For Index = LBound(FolderPath) + 1 To UBound(FolderPath)
Set OutlookFolder = OutlookFolder.Folders(Fold
If OutlookFolder Is Nothing Then Exit Function
Next Index
On Error GoTo 0
Set GetOutlookFolder = OutlookFolder
End Function
[End Code Segment]
Kevin
In the above example I made a mistake. The array passed to GetOutlookFolder must always start with the root folder or account name:
Set OutlookFolderObject = GetOutlookFolder(Array("Pe rsonal Folders", "Inbox", "MSN"))
Kevin
Set OutlookFolderObject = GetOutlookFolder(Array("Pe
Kevin
ASKER
kevin i really appreciate you taking the time now how can we include the msn mailbox into what you did before thanks then i'll be set
Public Sub TestRedemption()
Dim oSession As New Redemption.rdoSession
Dim objFolder As Redemption.RDOFolder
Dim oItems As Object
Dim oItem As Redemption.RDOMail
Dim att_Ment As Object
Dim sMessageBody As String
Dim sSubject As String
Dim sPriority As Integer
oSession.Logon , , , False, False
Set objFolder = oSession.GetDefaultFolder( rdoDefault Folders.ol FolderInbo x)'<<< i would like this to be msn or hotmail which ever i choose
Set oItems = objFolder.Items.Restrict(" [UnRead]=' true'")
'Set oItems = objFolder.Items
For Each oItem In oItems
If (oItem.UnRead) Then
sMessageBody = oItem.Body
sSubject = "From:" & oItem.Sender & vbCrLf & "To:" & oItem.To & vbCrLf & "Subject:" & oItem.Subject
sPriority = oItem.Importance
'oItem.MarkRead(True)
'oItem.Move()
If oItem.Attachments.Count > 0 Then
Set att_Ment = oItem.Attachments.Item(1)
End If
Else
End If
Next
Set oSession = Nothing
If Not oSession Is Nothing Then
If oSession.LoggedOn Then
oSession.Logoff
End If
End If
End Sub
Public Sub TestRedemption()
Dim oSession As New Redemption.rdoSession
Dim objFolder As Redemption.RDOFolder
Dim oItems As Object
Dim oItem As Redemption.RDOMail
Dim att_Ment As Object
Dim sMessageBody As String
Dim sSubject As String
Dim sPriority As Integer
oSession.Logon , , , False, False
Set objFolder = oSession.GetDefaultFolder(
Set oItems = objFolder.Items.Restrict("
'Set oItems = objFolder.Items
For Each oItem In oItems
If (oItem.UnRead) Then
sMessageBody = oItem.Body
sSubject = "From:" & oItem.Sender & vbCrLf & "To:" & oItem.To & vbCrLf & "Subject:" & oItem.Subject
sPriority = oItem.Importance
'oItem.MarkRead(True)
'oItem.Move()
If oItem.Attachments.Count > 0 Then
Set att_Ment = oItem.Attachments.Item(1)
End If
Else
End If
Next
Set oSession = Nothing
If Not oSession Is Nothing Then
If oSession.LoggedOn Then
oSession.Logoff
End If
End If
End Sub
Change this line:
Set objFolder = oSession.GetDefaultFolder( rdoDefault Folders.ol FolderInbo x)
To:
Set objFolder = GetOutlookFolder(Array("Ac count Name", "Inbox"))
Where "Account Name" is the root folder name such as "Personal Folders". I can't help any more than that as everyone's Outlook folder hierarchy is mostly customized.
Kevin
Set objFolder = oSession.GetDefaultFolder(
To:
Set objFolder = GetOutlookFolder(Array("Ac
Where "Account Name" is the root folder name such as "Personal Folders". I can't help any more than that as everyone's Outlook folder hierarchy is mostly customized.
Kevin
ASKER
thanks for your help kevin i really appreciate it
ASKER
Kevin i got it this
Public Function TestRedemption() As Integer
Dim oSession As New Redemption.rdoSession
Dim objFolder As Redemption.RDOFolder
Dim CdoFolder As Redemption.RDOFolder
Dim oItems As Object
Dim oItem As Redemption.RDOMail
Dim Attach_ment As Object
Dim sMessageBody As String
Dim sSubject As String
Dim sPriority As Integer
oSession.Logon , , , False, False
Set objFolder = oSession.GetFolderFromPath ("\\MSN\In box")
Set oItems = objFolder.Items.Restrict(" [UnRead]=' True'")
For Each oItem In oItems
If InStr(1, Message_Read, CStr(oItem.EntryID)) = 0 Then
Message_Read = Message_Read & CStr(oItem.EntryID) & "-"
'// /subject
sSubject = "From:" & oItem.Sender & vbCrLf & "To:" & oItem.To & vbCrLf & "Subject:" & oItem.Subject
'// /subject
sPriority = oItem.Importance
'/// checks for attachments
If Not oItem.Attachments.Count = 0 Then
Set Attach_ment = oItem.Attachments.item(1)
End If
End If
'// count messages
TestRedemption = TestRedemption + 1
Next
oSession.Logoff
End Function
Public Function TestRedemption() As Integer
Dim oSession As New Redemption.rdoSession
Dim objFolder As Redemption.RDOFolder
Dim CdoFolder As Redemption.RDOFolder
Dim oItems As Object
Dim oItem As Redemption.RDOMail
Dim Attach_ment As Object
Dim sMessageBody As String
Dim sSubject As String
Dim sPriority As Integer
oSession.Logon , , , False, False
Set objFolder = oSession.GetFolderFromPath
Set oItems = objFolder.Items.Restrict("
For Each oItem In oItems
If InStr(1, Message_Read, CStr(oItem.EntryID)) = 0 Then
Message_Read = Message_Read & CStr(oItem.EntryID) & "-"
'// /subject
sSubject = "From:" & oItem.Sender & vbCrLf & "To:" & oItem.To & vbCrLf & "Subject:" & oItem.Subject
'// /subject
sPriority = oItem.Importance
'/// checks for attachments
If Not oItem.Attachments.Count = 0 Then
Set Attach_ment = oItem.Attachments.item(1)
End If
End If
'// count messages
TestRedemption = TestRedemption + 1
Next
oSession.Logoff
End Function
what problem?