Applescript to send SMS message on Mail rule

I am an experienced MAC user but am inexperienced at Automator and Applescript. I would like to set a Mac Mail rule to trigger a SMS iMessage being sent that says something like "New Important Email". The recipient and SMS message text would always be the same (a notification that an important email arrived based on a Mail rule). I have searched the forum and found some similar, but old posts, that did not quite give sufficient description on how to do this. Too bad there is not a built-in method of doing this. I am an iPhone user, so it should be possible to have a Mail rule run an AppleScript to open the Messages app and tell the app to send me a SMS text. Any help would be appreciated. Thank you in advance for your help.

Posted on Jul 2, 2014 8:02 AM

Reply
12 replies

Jul 3, 2014 10:13 AM in response to KQS MD

You know what. Now that I played around with the VIP... Go to your iPhone...


Settings---> Notification Center---> Mail---> if you made a sender VIP, there should be a little section with VIP.


It would appear that setting senders as VIP will be able to be shown separate on your iPhone. In theory, you could turn off the "other senders" notifications but only see a notification from a VIP. If that is the case, then ignore my previous post of setting up a Rule in Mail to send a text message to you. Just go this route.



User uploaded file


KOT

Jul 3, 2014 1:46 PM in response to KQS MD

Hi,


Starter.

Mail (Mountain Lion): Use scripts as rule actions


The link to the Send part of the AppleScript linked in the John Lockwood post would be a partial Answer in that the info still needs to be grabbed from the Mail App.


I have looked for an AppleScript to grab the content of an email but no luck so far.



User uploaded file

9:46 pm Thursday; July 3, 2014


 iMac 2.5Ghz i5 2011 (Mavericks 10.9)
 G4/1GhzDual MDD (Leopard 10.5.8)
 MacBookPro 2Gb (Snow Leopard 10.6.8)
 Mac OS X (10.6.8),
 Couple of iPhones and an iPad

Jul 4, 2014 12:15 PM in response to John Lockwood

Hi,


That look useful.


I also looked at Automator.

I got this far with some dabbling.

User uploaded file

You seem to need the first bit to tell it to look at the mail app otherwise the second bit will just spin forever.

The From line does contain a Name (It happened to be just the description from the person sending the email and not from my Address Book.

The Result was just one email as wanted.


I couldn't work out if any of the Actions in the second column will extract the Subject and Content to put in to another app.

But there again I didn't devote a lot of time to it either.




User uploaded file

8:15 pm Friday; July 4, 2014


 iMac 2.5Ghz i5 2011 (Mavericks 10.9)
 G4/1GhzDual MDD (Leopard 10.5.8)
 MacBookPro 2Gb (Snow Leopard 10.6.8)
 Mac OS X (10.6.8),
 Couple of iPhones and an iPad

Jul 4, 2014 2:45 PM in response to Ralph-Johns-UK

Ok,


I started in the AppleScript Editor and New from Template for the Mail options.


I removed the comments (to make bits active) and removed bit I didn't need.


I then added the tell Messages app bit.


Whilst it acts like it runs I am not sure why it does not. (? the Messages section in th wrong place ?)


using terms from application "Mail"

on perform mail action with messages these_messages for rule this_rule

tell application "Mail"

set the message_count to the count of these_messages

repeat with i from 1 to the message_count

set this_message to item i of these_messages

set this_sender to the sender of this_message

get this_sender

try

set this_subject to (subject of this_message) as Unicode text

if this_subject is "" then error

on error

set this_subject to "NO SUBJECT"

end try

try

set this_content to (every character of content of this_message) as Unicode text

if this_content is in {"", "?"} then error

on error error_message

set this_content to "NO CONTENT"

end try

end repeat

end tell

tell application "Messages"

set myid to get id of first service

set theBuddy to buddy "+44iPhone Number" of service id myid

send "You have received Mail from " & this_sender & " regarding " & this_subject & " which says " & this_content to theBuddy

end tell

end perform mail action with messages

end using terms from



The First Service is what is top in the Messages > Preferences > Accounts list

On most peoples it will be the iMessages Account.


It is in Mail as a Rule which is set to a date limited check and a specific email sender.

User uploaded file

I still feel I am missing something.



User uploaded file

10:45 pm Friday; July 4, 2014


 iMac 2.5Ghz i5 2011 (Mavericks 10.9)
 G4/1GhzDual MDD (Leopard 10.5.8)
 MacBookPro 2Gb (Snow Leopard 10.6.8)
 Mac OS X (10.6.8),
 Couple of iPhones and an iPad

Jul 3, 2014 2:39 PM in response to Ralph-Johns-UK

Ralph Johns (UK) wrote:


Hi,


Starter.

Mail (Mountain Lion): Use scripts as rule actions


The link to the Send part of the AppleScript linked in the John Lockwood post would be a partial Answer in that the info still needs to be grabbed from the Mail App.


I have looked for an AppleScript to grab the content of an email but no luck so far.


Try something along the following lines


using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
repeat with eachMessage in theMessages
tell application "Mail"
set this_subject to subject of eachMessage
set this_body to content of eachMessage
end tell
if this_subject is "" then set this_subject to "No subject."
end repeat
end perform mail action with messages
end using terms from

Jul 3, 2014 4:11 AM in response to Kingoftypos

This issue is that I receive hundreds of emails a day and have extreme work hours (85 hours per week), which means I don't get a chance to look at email sometimes for a week or more. My work prevents me from using my MBP all day (university physician, days are spent in patient care activities which don't involve using email of any kind). Even filtering out the junk emails wouldn't help, because I am often just too fatigued from the regular work to even think about looking at email on my MBP or iPhone. That said, there are a few email senders that are super important and I want to know when I get a message from them. It is for this reason, I want my MPB, which is in "power nap" mode all day, to let me know by text message whenever an email comes in from a few choice sources. Thank you in advance for your help.

Jul 3, 2014 9:21 AM in response to KQS MD

First, if you still have 10.9.3 then the Power Nap is still working. If you have updated to 10.9.4, then the Power Nap might be broken. As myself and another person has complained about it not "waking up" every hour. Honestly if it wasn't for his post, I wouldn't of noticed. He has a 2012 MBP, while I have a 2012 Mac Mini, it was suggested that his MBP must be plugged in. But of course I had to mix things up when I said my Mac Mini wasn't doing the Power Nap either. lol


The only thing that I can think of ATM, is to set up a rule for those special senders.


Mail---> Preferences---> Rules---> Add Rule---> (Make sure it's on "Any" not all).


Select Sender is VIP (This will require you to make those special senders VIP)


Then to perform action. Select "Forward Message" And in the blank, put your phone number@your carrier address. If you don't know your carrier's address. Then just open your text messaging app and send a message to your email address. This will forward your emails to your phone's "text messaging" app. You can either read the email in that text messaging app, or view it in your email box.


If you have an iPhone, this could be easier. As you can open your Mail app on your phone. Go to the main screen for the email account. Click on Edit at the upper right corner. From that drop down list, there's a box for VIP. So if you can't read it in your text messaging app, at least you can easily read it in the Mail app.


There are a few other ways, but at least this way with the VIP. You can add/delete senders from your VIP list with out having to edit that "Rule".


KOT

Jul 3, 2014 10:06 AM in response to KQS MD

I am not sure the Messages application on the Mac can send SMS messages, obviously it can send iMessages to iOS (or Mac) devices but this is not the something as an SMS. Therefore if you want it to go to a dumb phone which cannot receive iMessages you may not be able to do it this way. An iPhone can try sending an iMessage and then fall-back automatically if needed to plain-ordinary SMS because it is a mobile phone and therefore has built-in SMS capabilities, a Mac does not.


There are various email to SMS gateways available but in general there is a cost associated with them.


Assuming an iMessage to an iOS or Mac device is sufficient have a look at the following website and see if this helps you along.


http://www.mikesel.info/send-an-imessage-with-an-applescript/


PS. There are also ways to connect what is effectively a mobile phone to a Mac and send the real SMS via the phone.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript to send SMS message on Mail rule

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