Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AppleScript to auto BCC emails from Apple Mail

I recently moved the email out of Entourage and into Apple Mail for a company I do business for. I created a rule for them which does not run automatically, see my other post <a href="https://discussions.apple.com/thread/3300257">here</a>. Having experimented with variations on the rule and searched for answers on the web I have come to the conclusion that I may not be able to get the rule to run automatically. I found various suggestions on the web for using Terminal to automatically BCC sent emails but the downside is that it appears that you then can't send BCC emails to anyone else without using Terminal to disable this, which is not an option.


The best alternative would appear to be an AppleScript but I can't find anything suitable. Can anyone suggest a script that can be added to an Apple Mail rule so that all emails sent from 'whoever@companydomain.com' are automatically forwarded to 'office@companydomain.com'

Posted on Aug 31, 2011 7:20 PM

Reply
27 replies

Nov 10, 2012 2:33 AM in response to twtwtw

Thanks for that, I've edited the LaunchAgent accordingly. Unfortunately the AppleScript doesn't appear to work. This is how it looks now


property lastForwardingDate : (current date)

property bccRecipientAddresses : {"whoever@companydomain.com"}


tell application "Mail"

set unforwardedMessages to messages of mailbox "Sent" of account "Company" whose date sent > lastForwardingDate

repeat with thisMessage in unforwardedMessages

set messageToForward to redirect thisMessage

tell messageToForward

repeat with thisRecipient in bccRecipientAddresses


makenewbcc recipientat end of bcc recipientswith properties {address:thisRecipient}

end repeat

set lastForwardingDate to date sent of messageToForward


send

end tell

end repeat

end tell



I'm currently testing it sending from one of my own email accounts to a different email account of mine but it isn't sending. The really odd thing is that I have the Herald extension installed in Mail and if I run the AppleScript I get a pop up message saying '1 Good Message' but there's no sign of anything.

Nov 13, 2012 9:57 AM in response to twtwtw

Ok. After a Restart all of a sudden I get something different if I open the script and try to run it, see below.


User uploaded file


I've looked back at the script to make sure the format wasn't still messed up and it looks exactly like what you suggested I use.


Also,although I created the launchd plist and put it in /LaunchAgents it doesn't appear to run. Do I need to do something else to enable it?

Feb 13, 2013 11:15 AM in response to twtwtw

I've been trying this for a while and once I got past the formatting issues it all seemed to work but I never have managed to get the script to automatically send as it should do.


What seems to happen is that I end up with a lot of hidden emails waiting to go that remain invisible until I quit and re-open Mail at which point I get lots of emails appear in Drafts and a whole lot of draft emails popping up all over the screen.


The launchd.plist is obviously doing what it should so I would guess that I've still got a formatting problem with the script.


User uploaded file

Maybe you could point me in the right direction as I don't seem to be able to see the wood for the trees.

Feb 13, 2013 4:09 PM in response to Sean Dale1

ok, my snippy moment has passed. 😉


My guess is that lastForwardingDate is the thing causing the issue. For example, the first time you run the script after a compile, you set lastForwardingDate to the current date, and then ask for messages sent after lastForwardingDate. Unless you're getting emails from the future that will never return anything. what I suggest you do is set the property to some older date for the first run, and then add in debuggers to see what lastForwardingDate is actually being set to as the script progresses.


Also, you might check to see if a real sender and subject line is included in your outgoing message, or if it's all bcc: or has no subject. If your preferences in Mail are set to give an alert when the subject is blank that could cause the block, and it may not like sending automated bcc: lists (which is spam-like behavior).

Oct 26, 2013 10:04 AM in response to twtwtw

Hello


I had a similar request, just to set up an auto-bcc on every outgoing mail from a certain account, but I got a different error in Apple Script


set bccRecipient to {"B1A0G@logemail.lessannoyingcrm.com"}


tell application "Microsoft Entourage"

set newMess to makenewoutgoing messageat end of outgoing messageswith properties {visible:true}

tell newMess

repeat with thisRecipient in bccRecipients as list


makenewbcc recipientat end of BCC recipientswith properties {address:thisRecipient}

end repeat

end tell

end tell


I got an error like this


tell application "Microsoft Entourage"

makenewoutgoing messageat end of every outgoing messagewith properties {visible:true}


--> error number -10014

Result:

error "Microsoft Entourage got an error: Handler only handles single objects." number -10014


I have no idea what it means, nor what I would change to make it work. Can you help?

Jun 6, 2014 4:05 AM in response to Sean Dale1

I have for the first time in years of using Mac Mail had what appears to be a common experience of a Sent email not having a copy in the mail box. This was an absolutely crucial email and I know it went because I received an Auto out of office reply from one of the recipients.


However in looking now to the tedious failsafe of having to bcc all sent emails to another address - my thinking was to create an address outside Mac Mail ( so that I am not disturbed by Incoming Email Notification for all my Mac Mail aliases).


Upon looking at Mail preferences I see there is STILL no option to Bcc automatically to any email address but Myself. ( There was a complaint about this in the thread still in 2011 and nothing appears to have been done about it despite my reading that there are many examples of Sent emails not being retained).


Does anyone have a solution which does not involve complex Apple Script stuff and other examples already discussed in this thread ( with due respect to the contributors whose technical expertise is awesome but too specialised for many)


best


MS

Jul 2, 2014 3:38 AM in response to musicspirit

I never did get the AppleScript options to work properly so in the end when the Mail Act On Mail extension (see http://www.indev.ca/MailActOn.html) included the ability to automatically BCC email addresses other than your own I used that. It's not free but it does work.


The only odd thing I found was that when I first installed it and set up a rule on any machine it wouldn't save that rule and I had to quit Mail then open it again and set up the rule again. A bit irritating but once I got past that it worked seamlessly.

AppleScript to auto BCC emails from Apple Mail

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.