Programmatically delete an item from the Sent items 
Author Message
 Programmatically delete an item from the Sent items

Hello all,

I've tried and tried, it's not worked and so here I turn.

Thanks to previous help from here, my application is able
to send a e-mail using Outlook and take a copy of that
sent item and place it into a public folder.  The sent e-
mail remains in the sent items folder as expected.

I wish my application to programmatically locate the sent
item and delete it permanently, leaving just the copy in
the public folder.  Is this actually possible or is the
sent items folder restricted in some way?

I am getting more familiar with coding with Outlook, but
the attached code does not do the job (I thought it
might). Please can you review this code and point me in
the right direction.

I thank you for your help.

John J.

Note: This routine is called right after the e-mail is
sent.

Sub DeleteSentItem()
    Dim oSentItemsFolder As Outlook.MAPIFolder
    Dim oDeleteFolder As Outlook.MAPIFolder
    Dim objOutlook As Outlook.Application
    Dim oMapi As Outlook.NameSpace
    Dim oItems As Outlook.Items
    Dim oItem As Outlook.MailItem

    Set objOutlook = New Outlook.Application
    Set oMapi = objOutlook.GetNamespace("MAPI")
    Set oSentItemsFolder = oMapi.GetDefaultFolder
(olFolderSentMail)
    Set oDeleteFolder = oMapi.GetDefaultFolder
(olFolderDeletedItems)
    Set oItems = oSentItemsFolder.Items
    Set oItem = oItems.Find("[Subject] = 'Test Message'")

    oItem.Delete

    Set objOutlook = Nothing
    Set oMapi = Nothing
    Set oSentItemsFolder = Nothing
    Set oDeleteFolder = Nothing
    Set oItems = Nothing
    Set oItem = Nothing
End Sub



Sun, 24 Jul 2005 22:41:24 GMT  
 Programmatically delete an item from the Sent items
Your code works perfectly fine for me.  Do you want the deleted message to
appear in your Deleted Items folder, or have it permanently deleted?  If the
latter, you'll have to use CDO to get a Message object, which you can
permanently delete using the Delete(False) method.  Setting it to True puts
it in the Deleted Items folder.

--
Eric Legault, MCSD
ADAPSYS - http://www.adapsys.ca


Quote:
> Hello all,

> I've tried and tried, it's not worked and so here I turn.

> Thanks to previous help from here, my application is able
> to send a e-mail using Outlook and take a copy of that
> sent item and place it into a public folder.  The sent e-
> mail remains in the sent items folder as expected.

> I wish my application to programmatically locate the sent
> item and delete it permanently, leaving just the copy in
> the public folder.  Is this actually possible or is the
> sent items folder restricted in some way?

> I am getting more familiar with coding with Outlook, but
> the attached code does not do the job (I thought it
> might). Please can you review this code and point me in
> the right direction.

> I thank you for your help.

> John J.

> Note: This routine is called right after the e-mail is
> sent.

> Sub DeleteSentItem()
>     Dim oSentItemsFolder As Outlook.MAPIFolder
>     Dim oDeleteFolder As Outlook.MAPIFolder
>     Dim objOutlook As Outlook.Application
>     Dim oMapi As Outlook.NameSpace
>     Dim oItems As Outlook.Items
>     Dim oItem As Outlook.MailItem

>     Set objOutlook = New Outlook.Application
>     Set oMapi = objOutlook.GetNamespace("MAPI")
>     Set oSentItemsFolder = oMapi.GetDefaultFolder
> (olFolderSentMail)
>     Set oDeleteFolder = oMapi.GetDefaultFolder
> (olFolderDeletedItems)
>     Set oItems = oSentItemsFolder.Items
>     Set oItem = oItems.Find("[Subject] = 'Test Message'")

>     oItem.Delete

>     Set objOutlook = Nothing
>     Set oMapi = Nothing
>     Set oSentItemsFolder = Nothing
>     Set oDeleteFolder = Nothing
>     Set oItems = Nothing
>     Set oItem = Nothing
> End Sub



Sat, 30 Jul 2005 00:06:39 GMT  
 Programmatically delete an item from the Sent items
Many thanks for the reply.  I have got it to work now, my
problem lay in the finding of the subject, which a later
message between yourself and Ken Slovak regarding 'Using
Apostrophies and quotes in filtering' helped me.

I also had the processing happening too soon after the
item was sent and have adjusted things.

I have got to admit that I was unaware of CDO and have
been reading up on it and that has given me many more
options.

Thank you and the others again for your help on this.

John James

Quote:
>-----Original Message-----
>Your code works perfectly fine for me.  Do you want the
deleted message to
>appear in your Deleted Items folder, or have it

permanently deleted?  If the
Quote:
>latter, you'll have to use CDO to get a Message object,
which you can
>permanently delete using the Delete(False) method.  

Setting it to True puts
Quote:
>it in the Deleted Items folder.

>--
>Eric Legault, MCSD
>ADAPSYS - http://www.adapsys.ca


message

>> Hello all,

>> I've tried and tried, it's not worked and so here I
turn.

>> Thanks to previous help from here, my application is
able
>> to send a e-mail using Outlook and take a copy of that
>> sent item and place it into a public folder.  The sent
e-
>> mail remains in the sent items folder as expected.

>> I wish my application to programmatically locate the
sent
>> item and delete it permanently, leaving just the copy in
>> the public folder.  Is this actually possible or is the
>> sent items folder restricted in some way?

>> I am getting more familiar with coding with Outlook, but
>> the attached code does not do the job (I thought it
>> might). Please can you review this code and point me in
>> the right direction.

>> I thank you for your help.

>> John J.

>> Note: This routine is called right after the e-mail is
>> sent.

>> Sub DeleteSentItem()
>>     Dim oSentItemsFolder As Outlook.MAPIFolder
>>     Dim oDeleteFolder As Outlook.MAPIFolder
>>     Dim objOutlook As Outlook.Application
>>     Dim oMapi As Outlook.NameSpace
>>     Dim oItems As Outlook.Items
>>     Dim oItem As Outlook.MailItem

>>     Set objOutlook = New Outlook.Application
>>     Set oMapi = objOutlook.GetNamespace("MAPI")
>>     Set oSentItemsFolder = oMapi.GetDefaultFolder
>> (olFolderSentMail)
>>     Set oDeleteFolder = oMapi.GetDefaultFolder
>> (olFolderDeletedItems)
>>     Set oItems = oSentItemsFolder.Items
>>     Set oItem = oItems.Find("[Subject] = 'Test
Message'")

>>     oItem.Delete

>>     Set objOutlook = Nothing
>>     Set oMapi = Nothing
>>     Set oSentItemsFolder = Nothing
>>     Set oDeleteFolder = Nothing
>>     Set oItems = Nothing
>>     Set oItem = Nothing
>> End Sub

>.



Sat, 30 Jul 2005 00:27:23 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Programmatically delete an item from the Sent Items Folder

2. How to delete selective items from Sent Items from PF Script

3. Programmatically delete Deleted Items folder once a day

4. Delete a Sent Mail from the Sent Item

5. programmatically selecting a tabstrip item without clicking an item

6. How do I delete an Item in a folder programmatically

7. Detecting an item move to Deleted Items folder

8. deleting an item or item set from a database

9. Howto trap MAPIFolder.Items.ItemAdd on Sent Items Folder

10. Meeting item when sent as item gives problems

11. Removal of attachments on email items in Sent items folder

12. Deleting MailItems from the Sent Items folder

 

 
Powered by phpBB® Forum Software