0

The Problem

I use Apple Mail on OS X 10.10 and have two mail accounts configured--one for work, and one for personal. More than once when I have composed a new message (not a reply), I have forgotten to check the "From:" address and sent a work message from my personal account and vice versa.

The Request

I am looking for a way to automatically set the "From:" account based on who the recipient is when I compose a new message. If the email is a reply, I want the default Apple Mail behavior (reply from the account that the message was received at).

For instance, say I want to send a message to my co-worker John. So I compose a new message and address it to his work email. I want Apple Mail to automatically detect his email address and set the "From:" account to my work email address.

Of course, the list of these email addresses would have to be created, but after the initial configuration the behavior should work automatically.

Another example: Say that the same co-worker John and I are also friends, and he sent me an email to my personal account to set up a time to get together outside of work. When I reply to his email, I would like the "From:" account to be my personal account, since this is the account that the email was originally sent to.

I don't understand how this seemingly common sense approach is not standard issue for email clients in 2015! Surely I can't be the only one who wants more than the universal default "From:" account that Apple Mail--and every other mail client--offers.

I've looked at the AppleScript dictionary for Apple Mail and read some threads here that suggest that GUI scripting may offer this functionality, but I don't have any experience with that.

Is there a way to accomplish this?

pnomads
  • 25
  • 2
  • 5

1 Answers1

1

The trick is getting Applescript to monitor the new messages being created. If you're willing to go the Keyboard Maestro route, you could remap command-N to an Applescript that gets the recipient address then creates a message with the appropriate sender (see http://www.macstories.net/tutorials/automating-mail-signatures-and-senders-with-applescript-and-keyboard-maestro/ and http://shawnblanc.net/2013/04/keyboard-maestro-email-signatures/ for some related examples).

Or run a script after you've entered the addresses. GUI scripting wouldn't be necessary. It would look something like this:

tell application "Mail"
set m to front outgoing message
set theRecipients to to recipients of m
  repeat with r in theRecipients
    if address of r is in {"mybuddy@fastmail.fm", "my buddy@gmail.com"} then
        set sender of m to "Personal Me <personalme@gmail.com>"
    end if
  end repeat
end tell

Getting Applescript to automatically do this with no intervention would require a daemon or some other way of monitoring events in Mail. Unfortunately there are no hooks built in.

Derick
  • 33
  • 5
  • `if (do shell script "echo -n " & quoted form of address of r & "|openssl sha1") is in thisHashList then` for better privacy. – fartheraway Apr 19 '15 at 09:51
  • @Derick- Thank you for your reply! After my initial post, I threw together a very hacky Keyboard Maestro macro of my own, so I'd like to try a more stable option first--the applescript option. Problem is, when I run the script, I get the error message "Mail got an error: Can’t get every to recipient of outgoing message id 1." number -1728 from every to recipient of outgoing message id 1". What's going on and how can I fix it? Thanks for your help! – pnomads Apr 20 '15 at 05:34