Fix: Mountain Lion “Apple Mail 6.0” problems with sender (reply-from) and mail folders/boxes

UPDATE – MARCH 17th 2013: This bug has now been fixed (only took Apple 7-8 months to do it!), with the latest release, OS X 10.8.3. So fire up Software Update and update your Mountain Lion! No more need for the Apple Script below.

Sorry for the long subject but it’s a bit hard to explain this issue in a subject line 🙂 First, let me explain the problem a little bit, but if you’re only here for the fix, scroll down to “The Solution”…

This bug/issue with Apple’s latest version of Mail, 6.0, in Mac OS 1.8 “Mountain Lion” primarily affects two kinds of users:

1) Those who use a unified mail inbox that gathers mail from multiple other accounts (such as me).

2) Those who move mail around to different mail folders on their Mac, either manually or via rules.

The problem is, once a mail has been moved away from the Inbox that is associated with the account you received the e-mail at, and you try to reply the e-mail, your “From” address is now changed to whatever address you have specified to be the one used for creating new e-mails.

This is a big problem if you use the same computer for work and home, or you are involved with several businesses. You don’t want somebody e-mailing you at [email protected] getting your reply from [email protected] – do you? That’s the risk you run when you use Mail 6.0 from Mountain Lion, this bug was not present in previous version of Mac OS X.

To elaborate on user #1 (how I do): I have a Gmail (well, Google Apps, but almost same difference) download e-mails from 3 other POP3 accounts, so I basically have e-mails from 4 different accounts in the same Gmail account. This makes it very easy for me to have my inbox synced across all devices.

On my Mac, before Mountain Lion, I could reply to any email sent to my company work e-mail, and my company work e-mail would be listed as “From”. Perfect. Now, Mail instead picks my private e-mail address (the one I have selected as default for new messages) to use as “From”, even though the mail was clearly addresses to a different address.

Same thing happens if you have rules that automatically put any mail with subject “[Project 123]” into a “Project 123”-folder, and you later decide to reply it, your reply will be sent from your private address and not the address the mail was sent to. Even if you manually move the mail to that particular folder.

More information/threads about this bug:

The Solution: AppleScript

After having sent enough e-mails from the wrong “From” address, I got tired of it and went searching for a (temporary) fix, and I found this post by Robert Silverstein on the Apple Discussion boards. His script had two problems, though:

1) It required a 3rd party app to actually run the AppleScript, in this case, “Spark”.

2) It would set the recipient e-mail as “From”, but only the e-mail address. This means your e-mails will now appear as being from “[email protected]”, ie. without your name shown, instead of the usual e-mail format being “Firstname Lastname <[email protected]>” or something like that. This means that recipients would no longer see my name when I e-mail them, but only my e-mail address.

I fixed both problems, so a big thanks to Robert for supplying his script that I have used to modify to my needs:

1) Launch Automator on your Mac. Easiest to invoke Spotlight and search for Automator. Once in Automator, create a new “Service”:

2) In the left column, search for “applescript” and drag the result to the right column, so it will look like this:

3) Remove all the default scripting from the Automator AppleScript window, and copy/paste the below AppleScript, so it looks like this (script below picture):

AppleScript to copy/paste is below – MAKE SURE that you insert your e-mail addresses in the “if SentTo = ” line in the middle. This script is made for 3 e-mail addresses, if you have less or more than that, modify accordingly, it should be pretty straightforward. Finally, this script assumes that you use the same “name/email” format for your different e-mail accounts, like “Firstname Lastname <[email protected]>”.  If you use “Firstname – Company <[email protected]>” instead, you need to modify the “set sender of theResult” line accordingly.

To see the format you are using, create a new message in Mail and look in the “From” drop-down box below the Subject box.

AppleScript:

[code]property sentTo : ""
property theResult : ""
tell application "Mail"
activate
set theSelection to selection
if ((count of theSelection) = 1) then
tell item 1 of theSelection
set sentTo to (address of recipient 1 of item 1)
set messageID to id of item 1
set theResult to (reply item 1 with opening window)
if sentTo = "[email protected]" or sentTo = "[email protected]" or sentTo = "[email protected]" then
set sender of theResult to "Firstname Lastname <" & sentTo & ">"
end if
end tell
else
display dialog ("Error: Select a message before running this script, or multiple recipients in selected message.")
end if
end tell[/code]

You can use the “Compile” button to make sure there are no errors in the script and to add the nice colors 🙂

4) At the very top of the Automator window where it says something along the lines of “Service receives…”, make sure you select “no input” and also make sure you select “Mail” in the drop-down box next to it:

From now, you can also test the script. Select a message in Mail 6.0, switch to Automator and click the “Play” button and see what happens – it should: Open up a reply message window, and have pre-selected the correct “From” address, basically, work like it used to do before Mountain Lion. If it does not, see if it throws an error and try to fix it.

5) Now you need to save your AppleScript as a service. Just hit CMD+S and it will ask for a name, make sure you can remember the name, or write it down somewhere (you need it later). I called mine for “Mail reply-from as recipient”, but anything will do, as long as it’s not something that another menu item is already using in Mail, so “Reply” will not work, etc.

6) It’s time to make it easy to use the script by assigning it a shortcut. I went with CMD+R, which means that the default “Reply” function in Mail no longer uses CMD+R, instead, that shortcut is assigned to my service, which basically does the same thing as the original “Reply”, except for two things:

  1. It does not have the “reply-from” bug. Yay!
  2. It does not have the nice eye-candy animation where a message pops up and turns into a new message window. Instead, with this script, your reply window will just popup instantly. Bummer (but I’ll live).
To assign the shortcut, open your System Preferences and go to Keyboard and Keyboard Shortcuts. Simply create a new shortcut, select “Mail” from the drop-down box, and also write the exact same name as you saved your service as, in my case, “Mail reply-from as recipient”. Finally, assign a shortcut, you can use CMD+R or maybe go with CMD+ALT+R if you like?

7) With the AppleScript saved through Automator as a Service, you should be able to switch to Mail 6.0, hit the “Mail” menu, expand “Services” and your service should be visible there:

Note that it also shows your assigned shortcut, in this case, “CMD+R”.

That’s it, folks! 

The Mail bug was not fixed in 10.8.1 as I had hoped for, which is why I decided to try and find a workaround. Hopefully it will be fixed in 10.8.2 but so far there are no reports of it. But hey, now that I’ve spent a lot of time writing this how-to article, I’m sure that with my luck, it will now be fixed in 10.8.2 which will probably also be released in a few days now, just to annoy me 😀   I wouldn’t mind that though… but for now, this at least works.

Ideas for improvement (that I’m unable to do with my limited AppleScript knowledge):

  • Have the script run-through all your accounts in “sender” and automatically pick the one that matches whatever “address of recipient” is, to avoid all the “if… then” for each e-mail address you want this script to work with.
  • If there are multiple recipients of an e-mail (In the “To” field), the script does not seem to work and will revert to default Mail 6.0 behavior, ie. just use your default e-mail address for new messages, when you reply. It’s possible that if your e-mail address is the first of all the “To” addresses, that it might still work as expected.
  • If possible: Add the same animation when the message window pops up, as if using the original “reply” method. Eye candy is part of the experience 🙂
  • Have the script send an e-mail to Apple each time you use it: “Hi Apple. Again, I had to use a custom script to fix your bugs. Wake up!!”. 
UPDATE (October 2012):
Stefan added two very helpful comments below, with his optimizations for the AppleScript above. Click here to read them.
UPDATE (March 2013): 
Yes, Apple has still not fixed this damn issue! Anyway, Ulf has posted another version of the script in the comments below, that you might want to check out as well, click here to read it.

25 thoughts on “Fix: Mountain Lion “Apple Mail 6.0” problems with sender (reply-from) and mail folders/boxes”

    • Hi Ivey,

      In line 11 in the script above, did you perhaps remove the “then” at the end of the line? Like, if you only need to use 2 e-mail addresses you probably removed one of the “or SenTo = ….” phrases and perhaps the “then” in the end, was removed by accident?

      Reply
  1. Hej Klaus

    Tak for tippet. Sidder selv og bander over samme problem, hvergang jeg sender med den forkerte firmaadresse som afsender – hvilket jeg typisk først ser efter der er svaret tilbage.

    Jeg tror dog lige jeg presser balderne og giver Apple én chance mere for at rette det først.

    Mvh
    Gunnar

    Reply
    • Hej Gunnar,

      Jeg presser også balderne og håber på en opdatering. Den kom desværre ikke i 10.8.1 som jeg havde håbet, så derfor håbede jeg på 10.8.2 men har læst (et enkelt sted, heldigvis kun ét sted) at det heller ikke er rettet i 10.8.2.

      Vi kan nok forøge chancerne ved at det bliver rettet ved at så mange som muligt logger ind med deres AppleID her, og opretter en bug report:
      http://bugreporter.apple.com
      Alternativt, bruger Feedback funktionen (hvor man dog ingen svar får): http://www.apple.com/feedback/macosx.html

      Mht. bug report, så er der flere der har fået svar tilbage at den er “closed as duplicate”, så det betyder da det i mindste at Apple er klar over det og der findes en original bug report på problemet – det er desværre bare ikke en indikation om at de har tænkt sig at rette det. Apple har jo desværre engang imellem den ide at de skal bestemme lidt for meget, så jeg er ikke 100% overbevist om at dette er en fejl de vil rette (hvis de overhovedet mener det er en fejl).

      Der er dog også et alternativt fix som ikke involverer AppleScript, som du evt. kan få – men det afhænger lidt af din situation om det vil fungere eller ej: Kort sagt, oprette en regel der flytter dine mails tilbage til de rigtige inbokse der vedrører den konto de er sendt til. Det betyder så bare at mails ikke længere er tilgængelig på den ene IMAP konto man har brugt til at hente dem ned med til at starte med. – Hvis altså det er sådan du bruger Mail.

      Reply
      • Hej Klaus

        Nu bruger jeg en række POP servere, og ikke IMAP. Jeg har meget automatiseret sortering af mails. Så ved ikke lige om dit trick vil gælde for mig?

        Mvh
        Gunnar

        Reply
        • Hej igen,

          Jeg tror det desværre ikke. Dit forbrugsmønster hører nok til i gruppe #2 som jeg nævner i starten af artiklen, hvor mit hører til i gruppe #1. Jeg sorterer stort set aldrig mine mails, men samler i stedet det hele i én indbakke på IMAP, og arkiverer løbende efter behov, og bruger “smart folders” til den smule “sortering” jeg har behov for.

          Så du er nok desværre nødt til at håbe på et Apple fix, eller forsøge dig med AppleScript tricket i artiklen.

          (Husk at læs artiklen på engelsk – bare i tilfælde hvis du kom herind via den danske version, som er Google Translate oversat, så der er nok lidt volapyk i forhold til den engelske version).

          Reply
  2. Wow, great, thanks. I knew I was not the only one experiencing this problem.
    Your script partially solves it for me.
    I have multiple e-mailaccounts configured in a Gmail account.
    So the OR for multiple addresses to respond with the same name is not covering it all.
    I would need multiple of these statements
    if sentTo = “[email protected]” then
    set sender of theResult to “Firstname Lastname ”
    end if

    if sentTo = “[email protected]” then
    set sender of theResult to “Firstname Lastname ”
    end if

    But just replicating these does not work. Do you have a suggestion how to implement this extension?

    Reply
    • Hi Lars,

      Unfortunately I do not know the answer to your problem if you need to assign a different name also. I would assume that using multiple of these would work:

      if sentTo = “[email protected]” then
      set sender of theResult to “Firstname Lastname ”
      end if

      But if it does not, then I have no ideas at the moment.

      Reply
  3. Since I really needed to fix this (the bug is driving me insane…), I took a stab at your wishlist and also fixed some other annoyances (sometimes your original script included the body of the original message twice for some weird reason).

    There is still one really annoying behavior; “selection” only picks the first message in a thread even though another message is selected. I can’t figure out how to fix this, but the manual fix is to double click the message so that it comes up in a separate window, then the script works ok.

    So, after a lot of hacking, I came up with the script below (to be used from Automator). I then use system preferences to bind this script to Cmd-R (add it to “Application Shortcuts” for “Mail.app” in “Keyboard” -> “Keyboard Shortcuts”.

    Note that to get “Reply All” behavior, you replace
    set theReply to reply selectedMessage
    with
    set theReply to reply selectedMessage with reply to all
    I created a copy of the script for this and mapped it to Shift-Cmd-R

    Here is the script:

    on run
    tell application “Mail”
    set theSelection to selection

    if ((count of theSelection) > 0) then
    set selectedMessage to item 1 of theSelection

    set addresses to address of every recipient of selectedMessage

    set sentTo to “”
    repeat with selectedAccount in accounts
    set accountemails to email addresses of selectedAccount
    repeat with accountemail in accountemails
    if addresses contains accountemail then
    set sentTo to full name of selectedAccount & ” ”
    exit repeat
    end if
    end repeat
    end repeat

    set theReply to reply selectedMessage
    tell theReply to set sender to sentTo
    tell theReply to set visible to true
    else
    display dialog (“Select a message before running this script.”)
    end if
    end tell
    end run

    Reply
  4. Here is the exact procedure to use Automator and keyboard bindings to get this working:

    Launch Automator (available in Applications)
    File -> New
    Select “Service” -> Click “Choose”
    Blank window appears
    In the left hand Column double-click on “Library” -> “Utilities” -> “Run Applescript”
    Replace all text with my script
    Click “Hammer” (which compiles and checks the script)
    In the panel above:
    Service receives “no input”
    in “Mail.app”
    File -> Save
    Save service as: “Mail – Reply to specific”
    Exit Automator

    Apple menu -> System Preferences
    Keyboard -> Keyboard Shortcuts -> Application Shortcuts
    Click “+”
    In the panel that appears:
    Application: “Mail.app”
    Menu Title: “Mail – Reply to specific”
    Keyboard Shortcut: Hit “Cmd-R”

    You’re done!

    Reply
    • I tried following your instructions as well as those of the original author. Everything works -except- for setting the service as a keyboard shortcut. No matter what I do, I can’t get Mail to see this new service – it just keeps reporting that “No services apply”.

      Any suggestions on what I could be doing wrong?
      Thanks
      Ralph

      Reply
  5. Hey! I saw your post as I had the same problem but then I realized I had messed up my settings on Mail.

    This may help your problem. I hope so: Basically I had to go through my SMTP outgoing servers and to make sure that all of my accounts were sending via the correct SMTP setting. (I had multiple Gmail accounts so they were all labeled “Gmail.”) I dug around in advanced settings/dialogues to make sure the inbox and smtp addresses matched.

    That’s it! 🙂 Maybe it’ll help, maybe it won’t but I figured it couldn’t hurt.

    Reply
  6. hi there.

    I have the same problem, and have some experience with AppleScript. based on the scripts you both wrote, here is my version.

    cheers,
    Gregory

    property myNames : {}
    property myAddresses : {}

    on run
       tell application “Mail”
          — only scan the Accounts if they’ve not been scanned before.
          if myNames is {} then
             set myAccounts to every account whose enabled is true
             repeat with a in myAccounts
                set end of myNames to a’s full name
                set end of myAddresses to a’s email addresses
             end repeat
          end if
         
          — get the selected message/s
          set msg to selected messages of front message viewer
          — for this version of the script, only reply to the first message
          set msg to msg’s first item
         
          — match the msg recipients with our account addresses
          set matchedAddress to false
          repeat with r in msg’s recipients
             repeat with a from 1 to myAddresses’s length
                if r’s address is in myAddresses’s item a then
                   set matchedAddress to true
                   exit repeat
                end if
             end repeat
          end repeat
         
          — generate Reply email
          — if the option modifier is down, Reply to All
          — requires installation of the keys shell utility.
          — the keys utility returns a text value of “0” or “1”.
          — http://brettterpstra.com/quick-tip-checking-for-modifier-keys-in-shell-scripts/
          if (“0” = (do shell script “/applications/keys option”)) then
             set myReply to reply msg with opening window
          else
             set myReply to reply msg with reply to all and opening window
          end if
          if matchedAddress then ¬
             set myReply’s sender to ¬
                “\”” & myNames’s item a & “\” ”
         
       end tell
    end run

    Reply
    • the last part of that should read:

            if matchedAddress then ¬
               set myReply’s sender to ¬
                  “\”” & myNames’s item a & “\” <” & (r’s address as rich text) & “>”

      Reply
      • sorry about this Klaus. perhaps you could clean up the replies.


        property myNames : {}
        property myAddresses : {}

        on run
           tell application "Mail"
              -- only scan the Accounts if they've not been scanned before.
              if myNames is {} then
                 set myAccounts to every account whose enabled is true
                 repeat with a in myAccounts
                    set end of myNames to a's full name
                    set end of myAddresses to a's email addresses
                 end repeat
              end if
             
              -- get the selected message/s
              set msg to selected messages of front message viewer
              -- for this version of the script, only reply to the first message
              set msg to msg's first item
             
              -- match the msg recipients with our account addresses
              set matchedAddress to false
              repeat with r in msg's recipients
                 repeat with a from 1 to myAddresses's length
                    if r's address is in myAddresses's item a then
                       set matchedAddress to true
                       exit repeat
                    end if
                 end repeat
              end repeat
             
              -- generate Reply email
              -- if the option modifier is down, Reply to All
              -- requires installation of the keys shell utility.
              -- the keys utility returns a text value of "0" or "1".
              -- http://brettterpstra.com/quick-tip-checking-for-modifier-keys-in-shell-scripts/
              if ("0" = (do shell script "/applications/keys option")) then
                 set myReply to reply msg with opening window
              else
                 set myReply to reply msg with reply to all and opening window
              end if
              if matchedAddress then ¬
                 set myReply's sender to ¬
                    "\"" & myNames's item a & "\" <" & (r's address as rich text) & ">"
             
           end tell
        end run

        Reply
        • Thank you for your script, Gregory.

          I still have faith that Apple will fix this, and 10.8.3 was seeded to developers this past week so I’m hoping it will come out to the masses soon and the bug has been fixed. If not fixed, then I will look further into your script and see if I can make it work myself as well 🙂

          Reply
          • Klaus, I hope they fix it too. but…

            there’s a small mistake in one of the last lines.
            (r's address as rich text)
            should be:
            (r's address as string)

            and if you decide to try this script, you’ll not need to edit it. it should work as is provided you’ve downloaded/installed the key utility executable in /Applications.
            cheers.

            Reply
  7. Thank you so much for the scripts above, they work great for me – I am now able to send replies automatically from the account the original mail was sent to, just like before Apple introduced this bug!

    However, another widely discussed bug remains. That is, mail keeps adding my address in the cc field on every reply mail I send. So I need to manually remove that before sending the mail – for each and every mail. Which is impractical, of course.

    Could this also be fixed by adding something to the scripts? I.e., something that automatically removes my mail address from the cc field? I tried fiddling around a little with the scripts but was not able to achieve the desired result unfortunately.

    Appreciate everyone’s effort on this!

    Reply
  8. Just noticed that my previous statement wasn’t entirely correct. The bug occurs only on reply-to-all, not on reply. I.e., whenever I do reply-to-all, Mail will add my own mail address to the cc field.

    Reply
  9. Okay, looks like I did it. It’s probably not pretty or optimized in any way but the following script does what the above scripts do, plus it also removes your address from cc and to of the reply-to-all mail:

    on run
    tell application “Mail”
    set theSelection to selection

    if ((count of theSelection) > 0) then
    set selectedMessage to item 1 of theSelection

    set addresses to address of every recipient of selectedMessage
    set theccRecipients to address of cc recipients of selectedMessage
    set thetoRecipients to address of to recipients of selectedMessage
    set theSender to sender of selectedMessage

    set sentTo to “”
    repeat with selectedAccount in accounts
    set accountemails to email addresses of selectedAccount
    repeat with accountemail in accountemails
    if addresses contains accountemail then
    set sentTo to full name of selectedAccount & ” ”
    set senttoAddress to accountemail
    exit repeat
    end if
    end repeat
    end repeat

    set theReply to reply selectedMessage with reply to all
    tell theReply to set sender to sentTo
    tell theReply to delete cc recipients
    tell theReply to delete to recipients

    repeat with a from 1 to count theccRecipients
    set insertccRecipient to item a of theccRecipients
    if insertccRecipient does not contain senttoAddress then
    tell theReply to make new cc recipient with properties {address:insertccRecipient}
    end if
    end repeat

    tell theReply to make new to recipient with properties {address:theSender}
    repeat with a from 1 to count thetoRecipients
    set inserttoRecipient to item a of thetoRecipients
    if inserttoRecipient does not contain senttoAddress then
    tell theReply to make new to recipient with properties {address:inserttoRecipient}
    end if
    end repeat

    tell theReply to set visible to true

    else
    display dialog (“Select a message before running this script.”)
    end if
    end tell
    end run

    Reply
    • Thanks Ulf, I’ll update the original post with a link to your comment, so readers are aware of your version as well.

      Reply
  10. I posted the script at https://discussions.apple.com/thread/4143652?start=60&tstart=0 , referencing this page here.

    Reply
  11. SO glad this issue has finally been fixed!!! It is a coincidence that today I was actually looking around online trying to find a solution, AGAIN. One website gave me the idea to search a different way for a solution. That search led me to your site and here it is you JUST posted that they updated Mountain Lion. Wild.

    Reply

Leave a Comment