Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bedouin

macrumors member
Original poster
Mar 3, 2011
95
7
In every version of OS X that I can remember until Sierra, there was an option in Mail to remove sent messages after a week, month, and maybe even a year.

A couple days ago I noticed that my sent mail folders were filled with messages from a couple months ago. I looked in the Mail preferences and saw that the option to delete sent messages after a certain period of time has been removed. Is there a way to get this back, perhaps through some plist wizardry? This is highly annoying.
 
The option is still available.
Screen Shot 2016-12-12 at 2.55.56 PM.png
 
In every version of OS X that I can remember until Sierra, there was an option in Mail to remove sent messages after a week, month, and maybe even a year.

A couple days ago I noticed that my sent mail folders were filled with messages from a couple months ago. I looked in the Mail preferences and saw that the option to delete sent messages after a certain period of time has been removed. Is there a way to get this back, perhaps through some plist wizardry? This is highly annoying.
I just checked after seeing your post and I have the same issue. I'm pretty sure there was an option on this screen to keep 30 days. Since updating to Sierra on Sept. 20 none of my sent items have been purged.

Screen Shot 2016-12-12 at 8.24.42 AM.png
 
Thanks! I'm hoping you find something.

Here is a screenshot from Mail in Yosemite by the way, for anyone who may think we are crazy :)

Screen Shot 2016-12-12 at 6.40.30 PM.png
 
Thanks! I'm hoping you find something.

Well, after a couple hours messing about I am nowhere. :mad:

From looking around in the Mail plist it looks like this command should fix it (to 60 days), but it does not.

Code:
defaults write com.apple.mail NumberOfDaysToKeepSentMessages 60

I can see the 60 change applied in the plist, but Mail does not seem to recognize it. Before the plist change that value was set to -1, which seems to be "never".

I even rebooted after updating the plist because since Mavericks plist files get cached, so you need to logout after any changes. I don't see any other values in the plist that look like they would do anything with sent message storage.
 
  • Like
Reactions: bedouin
Aside from switching to a new mail client (which I'm seriously considering because of this), are there any other solutions to accomplish the same thing?

By the way, have you tried switching it to 30 days? Maybe 60 is above the threshold, since there was only ever an option for one week, a month, or on exit.

EDIT: Another curiosity . . . this setting was done on a per-account basis (i.e., a separate value could be used for each account). Perhaps the setting is hidden in with preferences for the individual accounts?
 
  • Like
Reactions: Weaselboy
Aside from switching to a new mail client (which I'm seriously considering because of this), are there any other solutions to accomplish the same thing?

By the way, have you tried switching it to 30 days? Maybe 60 is above the threshold, since there was only ever an option for one week, a month, or on exit.

EDIT: Another curiosity . . . this setting was done on a per-account basis (i.e., a separate value could be used for each account). Perhaps the setting is hidden in with preferences for the individual accounts?
Yep... I tried all that. I even converted the plist to an XML file using plutil so I could read and edit it in Textedit. There is a setting for each account and I changed both on mine then used plutil to convert back to a binary plist.

I tried every method and variation I could find or think of and nothing seems to work. The setting does take in the plist, but it seems as if Mail is just ignoring it.
 
  • Like
Reactions: bedouin
I wonder whether they removed the functionality to stop the conversation view from becoming disjointed.

You could write an Applescript to do it, but I agree that it would be much better to have it as an option in the account settings.
 
Shrug. I disabled the conversation view then I minute it was first introduced to Mail. Not a fan.
 
I created an Automator workflow to identify the messages I want to delete (those older than 30 days in the sent boxes of certain accounts), but there is no action to actually delete them once you've identified them — unless I'm missing something. Passing the filtered messages onto the "Move to Trash" Finder action does not work, since they're not actually files. Any ideas?
 
In Applescript:

set theAccount to account of mailbox of this_message
set mailbox of this_message to mailbox "Trash" of theAccount

or maybe
move this_message to mailbox "Trash" of theAccount

I've not tried either, but I suspect it would work. You need to move it to the Trash mailbox within Mail not to the finder Trash.
 
I thought of going that route, but would prefer it to be automated and run every day automatically.

Oh me too.... but I am stuck right where you are with Automator. Please let me know if you come up with something. :)

For now, I figure I can just use the Smart Mailbox once a month or so and be all set.
 
Sounds like there are all kinds of landmines people are tripping over with Sierra that do not seem to have a fix. Guess I'll stay with El Capitan until these are fixed.
 
Oh me too.... but I am stuck right where you are with Automator. Please let me know if you come up with something. :)

I implemented your smart mailbox approach. I had to do things a bit differently though, because I have two accounts where I actually do want the sent messages to be saved. I had to create a smart mailbox identifying sent messages for the four accounts I want to purge messages from, and then make another smart mailbox to identify messages older than 30 days in that particular smart mailbox. Not a very "smart" way of having to deal with this.
 
  • Like
Reactions: Weaselboy
I do not know anything about Applescript.
I'm very new to Applescript and know very little about Automator :). I could probably write the entire thing in Applescript, but I believe you need a way to schedule it, and that requires a repeating calendar event and assumes you have a laptop running at that time. Or maybe it could be triggered by any mail being received? But again, that's only on the laptop.

A smart mailbox does seem the easiest way. Do you use an email provider that's not Apple/iCloud? Maybe a rule can be set there (via any web interface) to delete mails in the sent mailbox after 30 days? If I do get around to writing an Applescriot (just for fun, I don't need it myself as I use the smart mailbox method to clear out stuff only once a year!) I'll post it up here.
 
  • Like
Reactions: Weaselboy
It is not mentioned anymore in Apple’s help book either: https://help.apple.com/mail/mac/10.12/index.html?localePath=en.lproj#/cpmlprefacctmbox.

I cannot find the relevant preference on El Capitan either. I do not think that it is stored in ~/Library/Preferences/com.apple.mail.plist, or ~/Library/Mail or ~/Library/Containers, but rather in a database somewhere.

It is in the mail plist in this folder on Sierra. If you read this plist you can see changes applied to it from that Mail pref pane. If you look in that plist you can see where NumberOfDaysToKeepSentMessages has been changed from 30 to -1 on Sierra. It would be interesting to see what you show for that setting on El Capitan.

Code:
~/Library/Containers/com.apple.mail/Data/Library/Preferences/
 
It is in the mail plist in this folder on Sierra. If you read this plist you can see changes applied to it from that Mail pref pane. If you look in that plist you can see where NumberOfDaysToKeepSentMessages has been changed from 30 to -1 on Sierra. It would be interesting to see what you show for that setting on El Capitan.

Code:
~/Library/Containers/com.apple.mail/Data/Library/Preferences/

Just checked again, it is not there. There are few account-specific settings in there at all and this particular setting applies to the account, not the application as a whole. I did find ‘NumberOfDaysToKeepSentMessages’ in ~/Library/Mail/V2/MailData/Accounts.plist, but that plist has not been updated in months. There is no equivalent of Accounts.plist in V3, so it must be stored somewhere else now. I am wondering if it is in one of the databases instead in the MailData directory instead.
 
This will go through your email accounts (as defined in MailAccounts) and move any message in the Sent folder over 30 days old to the Trash folder. I'm a newbie at Applescript, but I've tested it and it does work.

Code:
set delDate to (current date) - (30 * days)
set MailAccounts to {"Account1", "Account2"}
set totalDeleted to 0
set MailRunning to 0

set choice to display alert "Deleting old sent emails" message "Will delete items earlier than " & date string of delDate buttons {"cancel", "Run"} default button "cancel" giving up after 10

if gave up of choice is true or button returned of choice = "cancel" then
    error number -128
end if

-- If Mail isn't running before this script executes, then kill it when the script ends
tell application "System Events"
    set ProcessList to name of every process
end tell
if "Mail" is in ProcessList then set MailRunning to 1

tell application "Mail"
   
    repeat with theAccount in MailAccounts
        set myMailbox to mailbox "Sent" of account theAccount
        set TrashBox to mailbox "Trash" of account theAccount
--     debug
--     display dialog (theAccount as rich text) & (name of myMailbox as rich text) & (name of TrashBox as rich text)
       
        set messagesToDelete to (messages of myMailbox whose date received is less than delDate)
        set totalDeleted to totalDeleted + (count of messagesToDelete)
        repeat with messageToDelete in messagesToDelete
            move messageToDelete to TrashBox
        end repeat
    end repeat
   
    display alert "Done!" message "Deleted " & (totalDeleted as rich text) & " emails" buttons {"OK"} giving up after 5
    if MailRunning = 0 then quit
end tell
 
  • Like
Reactions: Weaselboy
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.