Solved

Outlook 2007 redirect Save Sent Items folder by account

Posted on 2009-04-14
53
2,214 Views
Last Modified: 2012-05-06
In Outlook 2007 can I redirect "save sent items" folder by account. So if I am sending an email through POP3 account 'A' the sent message copy is saved to a specific folder vs the default 'Sent' folder
0
Comment
Question by:BigBadWolf_000
  • 28
  • 22
  • 3
53 Comments
 

Expert Comment

by:Diagnostics
Comment Utility
Do you not want it to go to your Sent message at all or is it okay if a copy also goes there? Under Tools there is a Rules and Alerts option which can create a rule that can send a copy of your sent item to a folder you specify.
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
Yeah I am aware of the copy rule workaround and the change folder for account . But, I want to stay in one PST and move the sent items with no copies.

Am open to using any plugins or code
0
 

Expert Comment

by:Diagnostics
Comment Utility
If I may ask, why is it that you don't want a copy in your Sent Items folder? This can help me assess your intentions and aide in possibly coming up with a solution.
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
So I keep my PST as clean and manageable with less bloat as possible and no manual interaction :D
Also the copy rule sets copy as Unread in specified folder
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
Am also aware of the "...save replies with original message" option, but this too does it for all folders
0
 

Expert Comment

by:Diagnostics
Comment Utility
Ouch, now I'm fresh out of ideas. Sorry.
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
It will not happen with Outlook native....need a plugin or code
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
Found this.....will test to see if it works :D
http://www.sperrysoftware.com/Outlook/Sent-Items-Organizer.asp
 
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
It ought to be possible using a rule and a script to detect the sending account ... will that help?

Chris
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
Yes I am open to using a script with a rule as long as it moves and not just copies...even better would be if script would move sent message to specific folder by recipient email domain or full email address
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
or moves the copy and deletes the original
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
Which accounts are to be addressed in this way and which folders for the related email to be saved to?

i.e. fred@fred.com ---> fred subfolder of sent items ... or whatever?

Chris
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
fred@fred.com Company (folder under root) > Fred (sub-folder under Company) > Sent (sub-folder under Fred)
preffered would be address w/o prefix just @fred.com
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
OK, one last question I think in order to proceed ... you haven't identified a specific email or range of emails affected.

You originally  said POP account A, I interpret from the last post you want to do it for every email.  If it is only for pop accounts a-z then can you identify how I know which pop accounts are to processed in this way?

Chris
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
range of emails....all sent through a POP Account A
There a currently different email domains (3 for now but more in future)  that I send/reply email to strictly through this AccountA...(Outlook 2007 picks it auto for replies/forwards and I pick manually for sends)

So for every email I send/reply through AccountA...
if to @xxx.com then put sent msg in folder Company\xcorp\sent
if to @yyy.com then put sent msg in folder Company\ycorp\sent
if to @zzz.com then put sent msg in folder Company\zcorp\sent

0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
DO you have multiple POP accounts ... it's easier if I can ignore that aspect

Chris
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
Yes I have multiple pop accounts, but I want sent items managed only for AccountA
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
To identify the correct definition can you run this macro which will return all of the POP3 accounts and copy the full text, (from the VBE immediate window) for the one in question here.

Chris
Sub itemisePOP3Accounts()

Dim olkApp As Application

Dim acct As Account
 

    Set olkApp = Outlook.Application

    For Each acct In olkApp.Session.Accounts

        Debug.Print acct.SmtpAddress

    Next
 

End Sub

Open in new window

0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
I ran the macro....in the VB Editor....it runs....nothing is output or displayed...
ran it in "this outlook session" and Module1....not result (see image below)
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
No offence ... the immediate window ctrl  + G to display
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
Duh! thanks... :D

It returns the email address associated with the different pop3 accounts....so I have four pop accounts.....just returns the email address for each...I dont want to post the email address here

ssss@domain1.com
dddd@domain2.com
aaaa@domain3.com
zzzz@domain4.com
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
the number 4 position is the one associated with the account in question
 
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
Understood ... i'll put a constant in that you'll have to set up for the account itself
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
sure not a problem....thanks
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
While I think about it.  In your outlook insert a new code module and put this line of code in:

Public Const Your_MailAccount_Name = "zzzz@domain4.com"

In this way this sensitive data is aved and if you need to copy the code to me it won't accidently get uploaded ... therefore don't put any code I supply in this same module use a second new code module for that purpose.

Chris
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
>>> if to @xxx.com then put sent msg in folder Company\xcorp\sent

Presumably I would be correct to say:
if to @xxx.com then put sent msg in folder Company\xxx\sent

But where is the root folder ... i.e. the folderpath.
PLace the cursor on the 'root' for the company folder and press enter on the following in the command line:

?application.ActiveExplorer.CurrentFolder.FolderPath

should be something like:
\\Personal Folders\Inbox\Company

Chris
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
FYI

I have draft code to do this which seems ok to me but is pending the correct folder path construct to finish adapting for your use.

Chris
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
got it will do - Public Const Your_MailAccount_Name = zzzz@domain4.com

@xxx.com then put sent msg in folder Company\xxx\sent would be fine
Path for sent messg folder for @xxx.com  = \\Personal Folders\Company\xxx\sent





0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
APologies I cannot fully test the code now but I tested as far as possible last night so place the following two subs into the new module ... the one without the public constant.

Now we need to execute the code.  In 'thisoutlooksession' in teh VBE select application and ItemSend.  In this sub add the line:

    checkPop Item

Now when you send an email that meets the criteria it should be moved as requested.  Let me know how it goes of course.

Chris
Sub checkPop(mai As mailitem)

Dim olkApp As Application

Dim cpy As String

Dim saveFolder As String

'Your_MailAccount_Name  is the account being analysed
 

    If mai.SendUsingAccount = Your_MailAccount_Name Then

        cpy = mai.Recipients.Item(1).Address & ";"

        cpy = Left(cpy, InStr(cpy, ";") - 1)

        cpy = Mid(cpy, InStr(cpy, "@") + 1)

        cpy = Left(cpy, InStr(cpy, ".") - 1)

        '\Personal Folders\Company\xxx\sent

        saveFolder = "\Personal Folders\Company\" & cpy & "\sent"

        mai.SaveSentMessageFolder = olNav2Folder(saveFolder, True)

    End If
 

End Sub
 

Public Function olNav2Folder(foldername As String, Optional createFolders As Boolean) As Object

Dim olApp As Object

Dim olNs As Object

Dim olfldr As Object

Dim reqdFolder As Object

Dim arrFolders() As String

Dim nestCount As Integer

 

    On Error Resume Next

    foldername = Replace(Replace(foldername, "/", "\"), "\\", "")

    If Right(foldername, 1) = "\" Then foldername = Left(foldername, Len(foldername) - 1)

    arrFolders() = Split(foldername, "\")

    Set olApp = CreateObject("Outlook.Application")

    Set olNs = olApp.GetNamespace("MAPI")

    Set reqdFolder = olNs.folders.Item(arrFolders(0))

    For nestCount = 1 To UBound(arrFolders)

        If Not reqdFolder Is Nothing Then

            Set olfldr = reqdFolder.folders

            Set reqdFolder = olfldr.Item(arrFolders(nestCount))

            If reqdFolder <> olfldr.Item(arrFolders(nestCount)) Then

                If createFolders Then

                    reqdFolder.folders.Add (arrFolders(nestCount))

                    Set olfldr = reqdFolder.folders

                    Set reqdFolder = olfldr.Item(arrFolders(nestCount))

                Else

                    Set reqdFolder = Nothing

                    Exit For

                End If

            End If

        Else

        End If

    Next

    Set olNav2Folder = reqdFolder

    Set olApp = Nothing

    Set olNs = Nothing

    Set olfldr = Nothing

    Set reqdFolder = Nothing

End Function

Open in new window

0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility

Did in thisOutlooksession...

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
checkPop Item
End Sub

Module 1...
Public Const Your_MailAccount_Name = "support@abc.com"

Module 2...
In path:        
your two subs, changed Company to ABC (folder in outlook is upper case so matched it)
changed 'sent' to 'Sent' (folder in outlook 'S' upper case so matched it)
saveFolder = "\Personal Folders\ABC\" & cpy & "\Sent"

In Outlook...
Made sure if recepients email is zzz@mydomain.com
then set sub-company folder name to mydomain (lowercase)

Sent email to zzz@mydomain.com from account support@abc.com
did above for another recipient with different domain

Did not work....message went to default Outlook Sent Items folder

-----------------------------------------

Just to test I tried using the pop account name as it appears in Outlook ...account properties....more settings....account name.

i.e. ABCcorp

got results below...

Error...

Run-time error '13':
Type mismatch

On Debug...
mai.SaveSentMessageFolder = olNav2Folder(saveFolder, True)

-----------------------------------------

Hope this helps, and thank you very much for staying with this.
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
For visual reference...

Snap1.jpg
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
saveFolder = "\Personal Folders\ABC\" & cpy & "\Sent
should be
saveFolder = "\\Personal Folders\ABC\" & cpy & "\Sent

Any change?
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
made change (added extra  \) ...tested ....did not work

0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
OOPS!

Replace
        mai.SaveSentMessageFolder = olNav2Folder(saveFolder, True)
with
        mai.SaveSentMessageFolder = olNav2Folder(saveFolder)

Chris
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
Made change, Did not work....
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
OOPS 2!

Replace
        mai.SaveSentMessageFolder = olNav2Folder(saveFolder)
with
        set mai.SaveSentMessageFolder = olNav2Folder(saveFolder)

Chris
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
Did that, unfortunately did not work....
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
In what way didn't work, ay relevant info?
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
Also examine the company etc in the potential  folder names for invalid characters:

Invalid Chars in Outlook:     / \ * ? < >
Invalid Chars in Exchange: / \ * ? < > | " ; : + [ ] & ~
Invalid Chars in OWA:        / \ * ? < > | " ; : + [ ] & ~ . #

Chris
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
Using outlook as a client no exchange involved.....when I send a message via AccountA the message ends up in the default 'Sent Items' folder no errors popup.
folder names have no invalid characters...they follow the email domain so there are no spaces...however one does have a -   i.e. xyz-asdf  ....but its does not work for any of the others either.
is there a way to log the actions of the macro to see whats happening???
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility

Is the new folder created
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
by the script...no...I already have the folders manually created...
\\Personal Folders\ABC\mydomain\Sent
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
Comment Utility
I've sat and tested and pasted/restructured but didn't quite figure the actual error.  I think there were a couple of overlapping error confusing me!

The code below works for sure so replace both the checkpop and the olNav2Folder functions from the snippet

Chris
Sub checkPop(mai As mailitem)

Dim fldr As Object

Dim olkApp As Application

Dim cpy As String

Dim saveFolder As String

'Your_MailAccount_Name  is the account being analysed
 

    If LCase(mai.SendUsingAccount) = LCase(Your_MailAccount_Name) Then

        cpy = mai.Recipients.Item(1).Address & ";"

        cpy = Left(cpy, InStr(cpy, ";") - 1)

        cpy = Mid(cpy, InStr(cpy, "@") + 1)

        cpy = Left(cpy, InStr(cpy, ".") - 1)

        '\Personal Folders\Company\xxx\sent

        saveFolder = "\\Personal Folders\Company\" & cpy & "\sent"

        Set fldr = olNav2Folder(saveFolder, True)

        Set mai.SaveSentMessageFolder = fldr

    End If
 

End Sub
 

Public Function olNav2Folder(foldername As String, Optional createFolders As Boolean) As Object

Dim olApp As Object

Dim olNs As Object

Dim olfldr As Object

Dim reqdFolder As Object

Dim arrFolders() As String

Dim nestCount As Integer

 

    On Error Resume Next

    foldername = Replace(Replace(foldername, "/", "\"), "\\", "")

    If Right(foldername, 1) = "\" Then foldername = Left(foldername, Len(foldername) - 1)

    arrFolders() = Split(foldername, "\")

    Set olApp = CreateObject("Outlook.Application")

    Set olNs = olApp.GetNamespace("MAPI")

    Set reqdFolder = olNs.folders.Item(arrFolders(0))

    For nestCount = 1 To UBound(arrFolders)

        If Not reqdFolder Is Nothing Then

            Set olfldr = reqdFolder.folders

            Set reqdFolder = olfldr.Item(arrFolders(nestCount))

            If reqdFolder <> olfldr.Item(arrFolders(nestCount)) Then

                If createFolders Then

                    reqdFolder.folders.Add (arrFolders(nestCount))

                    Set olfldr = reqdFolder.folders

                    Set reqdFolder = olfldr.Item(arrFolders(nestCount))

                Else

                    Set reqdFolder = Nothing

                    Exit For

                End If

            End If

        Else

        End If

    Next

    Set olNav2Folder = reqdFolder

    Set olApp = Nothing

    Set olNs = Nothing

    Set olfldr = Nothing

    Set reqdFolder = Nothing

End Function

Open in new window

0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
Did it...no luck...did not work...same results as before.

Chris, are you testing with a POP account on Outlook 2007?


0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
Absolutely.

Try deleting the specific sub folder ... when working the script will create the folder unde company.  It will then give some evidence to work off.

Chris
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
Deleted the sub folder under company....no effect....script did not create sub folder and sent item remains in Sent Items folder.
Does your script wait for the message to go to Sent Items folder and then move it to the desired folder? if not ...maybe thats a direction that may work.
The reason I say that is cause I downloaded a trial version of the commercial sw I mentioned in the above posts. Its a plugin not a vb module.I notice the sent message first goes to the Sent Items folder and a second later it is moved to the desired folder.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
'my' solution actually changes the email as part of the send action so that it is saved straight away to the required folder.  I will repost the code now to 'stop as soon as it's triggered so let's see if it runsd at all!

If it stops then press F8 time and again and see which lines of code are executed.

Chris
Sub checkPop(mai As mailitem)

Dim fldr As Object

Dim olkApp As Application

Dim cpy As String

Dim saveFolder As String

'Your_MailAccount_Name  is the account being analysed
 

    Stop

    If LCase(mai.SendUsingAccount) = LCase(Your_MailAccount_Name) Then

        cpy = mai.Recipients.Item(1).Address & ";"

        cpy = Left(cpy, InStr(cpy, ";") - 1)

        cpy = Mid(cpy, InStr(cpy, "@") + 1)

        cpy = Left(cpy, InStr(cpy, ".") - 1)

        '\Personal Folders\Company\xxx\sent

        saveFolder = "\\Personal Folders\Company\" & cpy & "\sent"

        Set fldr = olNav2Folder(saveFolder, True)

        Set mai.SaveSentMessageFolder = fldr

    End If
 

End Sub

Open in new window

0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
Did it ...same results
I have the images in exact sequence of what line it runs after each F8 starting with Stop....


F8-1.JPG
F8-2.JPG
F8-3.JPG
F8-4.JPG
F8-5.JPG
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
So the mail account name isn't being detected ... it's nnot ther case as that is forced to low.

SInce you cannot advise the mail account you need to double check the definition of your_mailaccount_name in teh public file.

When the code stops on that line type in the immediate window:

?mai.SendUsingAccount
then
?Your_MailAccount_Name

And line the two outpus up and see where they are different.

Chris
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
IT WORKS!!! it was the 'Your_MailAccount_Name' constant....

A summary of why...for reference...

"To identify the correct definition can you run this macro..."
This script provided the email address of AccountA (aaa@mydomain.com)
So we used...
Public Const Your_MailAccount_Name = "aaa@mydomain.com"

In my message "04/17/09 09:18 AM, ID: 24169361" I mentioned...
"Just to test I tried using the pop account name as it appears in Outlook ...account properties....more settings....account name."
But this caused an error cause the script had a few ooops' at the time

I never tried that again...till I saw your latest post and changed the public constant to....
Public Const Your_MailAccount_Name = "AccountA"
AccountA is the name given to the account in "more Settings" in account properties..see image below.

It works great......THANK YOU,THANK YOU,THANK YOU,THANK YOU,THANK YOU,THANK YOU, VERY MUCH...You are AWESOME...and thanks for being patient and staying with me on it. I am estatic.

Snap3.jpg
0
 
LVL 14

Author Closing Comment

by:BigBadWolf_000
Comment Utility
Thank You!!!
0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
Steady on! ... you'll burst a blood vessel ;o)

Glad to help in the end and sorry it took so long to close it out but I have learned, (I hope) to allow for the displayed name.

Chris
0
 
LVL 14

Author Comment

by:BigBadWolf_000
Comment Utility
hahahhahahahhah....in the words of Maya Angelou....All great achievements require time...I learnt a lot too... :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now