View Single Post
  #3  
Old May 1st 07, 06:32 AM posted to microsoft.public.outlook.program_vba
DG
external usenet poster
 
Posts: 31
Default Cache Mode Not allowing Sent Folder Update

Dmitry, that worked perfectly as you have been telling me for the past few
weeks. It just took me a while to "get it". I converted your original C code
to VB.net using some help out there. My only issue is how to convert "Item"
to Redemption.SafeMailItem:

Public objFolder As Outlook.MAPIFolder
Public WithEvents objFolderItems As Outlook.Items

Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Startup

'Used to watch over the Sent Items list
Dim objOutlook As Outlook._Application
objOutlook = New Outlook.Application()
Dim objNS As Outlook._NameSpace = objOutlook.Session
objFolder =
objNS.GetDefaultFolder(Outlook.OlDefaultFolders.ol FolderSentMail)

objFolderItems = objFolder.Items
AddHandler objFolderItems.ItemAdd, AddressOf objFolderItemAdded
End Sub

Public Sub objFolderItemAdded(ByVal Item As Object)
Public sentItem As Redemption.SafeMailItem

MsgBox("Item was added!!!")
sentItem = New Redemption.SafeMailItem

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''
'This line fails
sentItem.Item = Item
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''

SentItem.SaveAs........blah blah blah

End Sub

Thanks again Dmitry

"Dmitry Streblechenko" wrote:

Use the Items.ItemAdd event on the Sent Items folder contents table rather
than wait for a newitem to appear in the folder.
Besides being extremely ineffcient, your code does not let the Windows
message pump run (which is used by the MAPI notification mechanism)

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

"DG" wrote in message
news
--Outlook 2003 sp2
--VSTO 2005

My goal is to capture the e-mail in the Sent Items folder that was just
sent
by the user. If Cache Mode is enabled, I never "get" the e-mail just sent,
I
only get the last e-mail to enter the queue. If I remove Cache Mode, it
works
like a champ, I get the e-mail just sent by the user. I have added delays,
but nothing works. Here's the code:

......
Dim loopStartTime As Date = Date.Now
Dim numBeforeSent, numAfterSent As Integer

'objFolder is the Sent folder
numBeforeSent = objFolder.Items.Count

'_thisMail is MailItem
_thisMail.Send()

numAfterSent = objFolder.Items.Count

While Not numAfterSent numBeforeSent
If DateDiff(DateInterval.Second, loopStartTime, Date.Now) 30 Then
MsgBox("Unable to continue." & vbCrLf & "Reason: Unable to find the
email in the 'Sent Items' folder.", MsgBoxStyle.Critical)
Exit Function
Else
numAfterSent = objFolder.Items.Count
End If

End While

'''''''ONLY WORKS IN NON-CACHE MODE
sentItem.Item = objFolder.Items.GetFirst


How can I get the latest e-mail delivered to the Sent Items folder if I am
in Cache mode?




Ads