• Subject: How to read RECIPIENT and set SaveSentMessageFolder accordingly
  • Author: Axel Gehrke
  • Date: 18 Jan 2010
  • References:
OK, I'm try-and-erroring the following code to help me with keepingmy SentItems Box clean. After clicking the send button, I created a message box to ask me if I wanna delete the e-mail. YES will set the SaveSentMessageFolder as a subfolder "delete" in my SentItems box, which I can delete without looking at each mail again. NO should start further analysis of the RECIPIENT and set the SaveSentMessageFolder to an external OutlookDataFile "personal.pst". But I can't make Outlook pick up the recipient's address to compare it and set the SaveSentMessageFolder accordingly. Can somebody please help me how to define the variable(s) correctly and the "Else" section in the code below? Thanks, Axel Public Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) On Error Resume Next Dim myOlApp As Outlook.Application Dim myNamespace As Outlook.NameSpace Dim myPSTspace As Outlook.NameSpace Dim itemMail As Outlook.MailItem Dim mySentItems As Outlook.MAPIFolder Dim mySentDel As Outlook.MAPIFolder Dim myPSTSent As Outlook.MAPIFolder Dim myPSTSentTemp As Outlook.MAPIFolder Dim myRecipient As Outlook.Recipient Set myOlApp = CreateObject("Outlook.Application") Set myNamespace = myOlApp.GetNamespace("MAPI") Set myPSTspace = myOlApp.GetNamespace("MAPI") Set mySentItems = myNamespace.GetDefaultFolder(olFolderSentMail) Set mySentDel = mySentItems.Folders("delete") Set itemMail = myOlApp.ActiveInspector.CurrentItem 'Check for deletion option Prompt$ = "Store e-mail in Sent Items\delete?" If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check 4 deletion") = vbYes Then 'If deletion is picked, than store in (and possibly create) folder Sent Items\delete 'Create Folder "delete" to "Sent Items" if necessary If mySentDel Is Nothing Then Set mySentDel = mySentItems.Folders.Add("delete") End If Set itemMail.SaveSentMessageFolder = mySentDel 'If not, check recipients and store in designated archive file / folders '!!!THIS IS WHERE MY PROBLEM IS!!! Else 'Add storage file myPSTspace.AddStore "C:\Outlook\personal.pst" 'Get root folder of that file Set myPSTSent = myPSTspace.Folders.GetLast myRecipient = itemMail.Recipient If itemMail.Recipient = "jon.grande@gmail.com" _ Set myPSTSentTemp = myPSTSent.Folders("First Level") Set myPSTSentTemp = myPSTSentTemp.Folders("Second Level") Set myPSTSentTemp = myPSTSentTemp.Folders("Third Level") Set itemMail.SaveSentMessageFolder = myPSTSentTemp ElseIf itemMail.Recipients = "myself@gmail.com" Then Set itemMail.SaveSentMessageFolder = mySentDel End If End If itemMail.Send Set myOlApp = Nothing '... End Sub Submitted via EggHeadCafe - Software Developer Portal of Choice Resharper for Visual Studio .NET 2005 - Product Review http://www.eggheadcafe.com/tutorials/aspnet/a1fb97b8-be1b-4ba5-9db9-94b0248bc402/resharper-for-visual-stud.aspx
18 Jan 2010How to read RECIPIENT and set SaveSentMessageFolder accordingly.Axel Gehrke
18 Jan 2010\ Re: How to read RECIPIENT and set SaveSentMessageFolder accordingly.Sue Mosher [MVP]
18 Jan 2010   \ Look for patterns in Recipient Address.Axel Gehrke
18 Jan 2010      \ Re: Look for patterns in Recipient Address.Sue Mosher [MVP]
Contact Us
All times are in (US) Eastern Daylight Time (GMT -4:00)