Copy sent emails to IMAP folder

B

Brian

I am after code that moves a copy of sent emails to an IMAP
folder named "Sent".

I have it set up presently as a rule but am wanting to do it in VBA.

Thanks in advance,

Brian
 
B

Brian

Thanks Michael,

Forgetting about the IMAP folder for one minute. I think the code is;
--------------------------------------------------------------------------
Private Sub olSentItems_ItemAdd(ByVal Item As Object)
Item.Move
Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
End Sub
--------------------------------------------------------------------------
I put this in the VB editor in module 1, but nothing seems to happen and
it is not listed in the Macros list. I have turned off Macro security.

Any more suggestions please.

Cheers
 
M

Michael Bauer

Am Thu, 1 Dec 2005 05:42:03 -0800 schrieb Brian:

Events can be received in class modules only, e.g. in "ThisOutlookSession".
Additionally you need to subscribe to the event, example:

Private WithEvents olSentItems as Outlook.Items

Private Sub Application_Startup()
Set olSentItems = [whataver folder´s items you want to watch]
End Sub
 
B

Brian Tetlow

Thanks Michael,

I'm a bit confused.

Your previous post advised;

"Brian, you can use the ItemAdd event of SentItems folder. In tha
event
call the Item´s Move function."

So, do I forget about the code above and use this one.

"Private WithEvents olSentItems as Outlook.Items

Private Sub Application_Startup()
Set olSentItems = [whataver folder´s items you want to watch]
End Sub"

And if I don't have "Save copies of messages in Sent Items folder
checked, should
I set the watch to the outbox.

EG: Private WithEvents olSentItems as Outlook.Items

Private Sub Application_Startup()
Set olSentItems = outbox
End Sub"

Thanks
 
M

Michael Bauer

Am Fri, 2 Dec 2005 11:21:12 +0100 schrieb Brian Tetlow:

Sorry, my fault. Instead of SentItems´ ItemAdd just use the
Application_ItemSend.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim oMail As outlook.MailItem

If TypeOf Item Is outlook.MailItem Then
Set oMail = Item
Set oMail = oMail.Copy
oMail.Move GetFolder("HereYourTargetFolder")
End If
End Sub
 
B

Brian Tetlow

Thanks Michael

This is what I came up with in the end and it seems to work;

Dim IMAPSentFolder As MAPIFolder
Private WithEvents olSentItems As Items

Private Sub Application_Startup()
Dim MySent As Object
Set objNS = Application.GetNamespace("MAPI")
Set MySent = objNS.GetDefaultFolder(olFolderSentMail)
Set IMAPSentFolder = objNS.Folders("Brian's Mail").Folders("Sent")
Set olSentItems = MySent.Items
End Sub

Private Sub olSentItems_ItemAdd(ByVal Item As Object)
Item.Move IMAPSentFolder
End Sub

Private Sub Application_Quit()
Set objNS = Nothing
Set MySent = Nothing
Set olSentItems = Nothing
Set IMAPSentFolder = Nothing
End Su
 
Top