none
How to find an email from sent items? RRS feed

  • Question

  • Hi

    I'm trying to find the last send email from sent items. Is it possible ?

    I mean with TO address, Subject and email send time....

     

    Thanks & regards

    Bobbin

    Monday, January 30, 2012 3:21 PM

All replies

  • Grab reference to SentItems folder by means of Session.GetDefaultFolder (olFolderSentMail) and grab table for that folder. Use sort function to sort by "SentOn" property descending. Either iterate untill you find item of MessageClass 'IPM.Note' or use restriction option on table to filter by message class.
    Monday, January 30, 2012 3:34 PM
  •  

    Try

    set Items  = Application.session.GetDefaultFolder(olFolderSentMail).Items
    Items.Sort "[ReceivedTime]", true
    if Items.Count > 0 Then
      set Item = Items.Item(1)
      MsgBox Item.Subject
    End If

     


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    Monday, January 30, 2012 3:36 PM
  •            
    Hi
    I just convert the above code like this.  i am always getting 0 as item count. can anyone  point me where is the error.
    Outlook.MAPIFolder folder = (MAPIFolder)this.OutlookNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
                    Outlook.Items AllSentItems = folder.Items;
                                AllSentItems.Sort("[SentOn]", true);
                                MessageBox.Show(AllSentItems.Count.ToString()); // here i am getting 0
                                //Items.Sort "[ReceivedTime]", true
                                if (AllSentItems.Count > 0)
                                {
                                    Outlook.MailItem SentMail = (Outlook.MailItem)AllSentItems[1];
                                    MessageBox.Show(SentMail.Subject);
                                }
    thanks
    bobbin
    Monday, January 30, 2012 4:36 PM
  • Dumb question, but are you sure there are actually items in the Sent Items folder?

    How do you initialize the OutlookNamespace object? Do you call Logon for the right profile?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    Monday, January 30, 2012 8:41 PM
  • Hi  Dmitry

    I wrote the above code just after send a mail.

     

     

    ((Outlook.ItemEvents_10_Event)mail).Send += new ItemEvents_10_SendEventHandler(Mail_Send);
    
    mail.Send();
    
    Outlook.MAPIFolder folder = (MAPIFolder)this.OutlookNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
    Outlook.Items AllSentItems = folder.Items;
    AllSentItems.Sort("[SentOn]", true);
     MessageBox.Show(AllSentItems.Count.ToString()); // here i am getting 0
                                
    if (AllSentItems.Count > 0)
    {
          Outlook.MailItem SentMail = (Outlook.MailItem)AllSentItems[1];
          MessageBox.Show(SentMail.Subject);
    }
    

     

    In my outlook i have 2 accounts. I'm not using the first one. So there is no mails in sent folder. I am using the 2nd account. In it there are so many mails.

    I think its take first account, so its show the 0, because when i delete the first account and tried i got the correct mail count.

    My question : Is it any problem when the client have more than one account? IF it have problem, how can we overcome that?

    I think this reply will give you the better idea about my problem.

    Thanks

    Bobbin Paulose

    Wednesday, February 1, 2012 1:37 PM
  • few things:

    1. do not expect mail to appear in sent items folder right after you invoke 'send' function - attach your add-in to event ItemAdded on SentItems.Items collection and act only when event is rised

    2. there is Stores property on Namespace object (Application.Session) that allows you to iterate through all the stores configured in your outlook, you can either iterate through them and call code to get sent items folder, etc. OR you can hardcode which Store name should your code attach to and use it as indexer into Stores collection, all other code stays unchanged.

    Wednesday, February 1, 2012 1:51 PM
  • Sending is an asynchronous process, so the item will be moved to the Sent Items folder only after the transport provider actually sends the message (could be seconds or even minutes after the mesage is sent).

    Where does the message end after you send it? Can you actually see it in the *default* Sent Items folder?

    How many stores do yo uhave?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    Wednesday, February 1, 2012 1:58 PM