Automators 2: Email Automation

5 Likes

Great episode!
Small correction, David, you forgot the workflow-link to Rose’s workflow to mail the last taken image on your macsparky-post…

@MacSparky Love the additional short videos. Just one remark: Could you decrease the volume of the intro-/outro jingle in the future (or increase the volume of your voice recording)?
Thanks a lot

2 Likes

Is this in the video or the podcast? :slight_smile:

Just in the videos, the volume levelling in the podcast is spot on :ok_hand::slightly_smiling_face:

3 Likes

FastMail’s Sieve Scripts are very powerful for email automation.

Example: I have several service providers who email me when a new receipt is available, without adding that receipt to their email. I have to download the receipt manually from their site when I want to archive it. I use a Sieve script to automatically add an action to Remember The Milk (RTM), my trusted GTD system:

if allof(
  header :contains ["From"] "no-reply@provider.com", 
  header :contains ["Subject"] "Your receipt" 
) { notify :method "mailto" :options ["<import-address>@rememberthemilk.com"] :message "Archive Provider receipt #Personal #now #@pc @Home https://www.provider.com/receipts"; }

Whenever I get an email with the title “Your receipt” from email address "no-reply@provider.com" FastMail will send a newly generated email to my RTM import email address with a title confirming to the RTM Smart Add syntax to make sure that a task “Archive Provider receipt” to the list “Personal” with the tags “now” and “@pc” for location “Home” and URL “https://www.provider.com/receipts”.

Note: this happens server side, so no manual action in an email client needed :smiley:

2 Likes

I’ve been using FastMail for years and had no idea about the Sieve Scripting! I’ll have to look into this!

1 Like

Re: the guy at David’s daughter’s school not using BCC

During my student teaching last year, this was an unfortunately common practice. Not out of ignorance, however, but because of problems with spam filters when everyone was set to BCC (not sure if it was on the school end or the parent end, but the stated explanation was based on how many people were BCCed.) It was a G Suite school for what it’s worth. The real problem is the lack of listservs in education in 2018 (popular school grade/info provider PowerSchool gutted listservs built into the class lists, and as someone who just set up half a dozen without any users even, Google Groups is more than a bit tedious as a solution)

1 Like

I would love to do the “older than x days” tip to get rid of older crud clogging up my inbox but in the new layout of Gmail the “create a filter from this search” link is missing? How do I do it without it??

Hi, I’m starting to dabble into TextExpander and AppleScript, adapting the provided snippets and scripts to my needs, but I cant seem to use the applescripts correctly.

As an example, I wanted to edit Davids “recipients name script” and add an “else” parameter, when the recipients name consists of 3 words (fe. “Dr. John Smith”) to return the third word from the name, but I cannot get it to work. This is what I tried:

tell application "System Events"
tell process "Mail"
	tell text field "To:" of window 1
		if UI element 1 exists then
			set theToRecipient to (value of UI element 1)
			if (count words of theToRecipient) is 2 then return word 2 of theToRecipient
		else
			if (count words of theToRecipient) is 3 then return word 3 of theToRecipient
		end if
	end tell
end tell

end tell

Doesn’t work. Can someone help? Thanks!

Looks like you have a nested if, outer level checking a UI element existence and the inner one the length of the name. But the additional check for the name has been applied to the outer level if.

Try getting rid of the else.

2 Likes

Great episode guys!

One of the ways I’ve automated my email is by developing a 100% hands-off approach to dealing with receipt emails. i.e. Receipts I get from online services like MailChimp I have a detailed description of the workflow here, but in summary:

  1. I have email rules set up on Google or iCloud[dot]com (a lesser known feature of iCloud that means your Mac doesn’t have to be turned on to run email rules) to forward emails from certain senders or based on the subject line to Zapier (email trigger).
  2. I have two Zaps to handle the two types of emails: 1) Receipt attached the email. Zapier downloads the attached PDF and saves to an “Action” folder in Dropbox. 2) Email body is the receipt. Zapier uses CloudConvert to convert the email into a PDF and saves the output file to my “Action” folder in Dropbox.
  3. Hazel watches the “Action” folder and renames and moves the receipt to my accounting folder.

So after receiving one of these emails I usually just check my MacOS notifications to confirm that Hazel processed the file and I can simply archive the email.

It’s a handy workflow and because I receive a fair few emails like this, it saves me a fair bit of time each month.

3 Likes

That did the trick, thanks! :ok_hand:

Not a textexpander subscriber so used keyboard Maestro for my apple mail automation.

@RosemaryOrchard I dont suppose its possible to share the macro for using KM to create and send an email based on a file being there? BTW loving the show!

I downloaded David’s Auto+Name+Email.textexpander snippet, but I don’t use Mail.app. I use Kiwi for Gmail. I substituted that for Mail (as per below) but it doesn’t work. Any suggestions?

tell application "System Events"
	tell process "Kiwi for Gmail"
		tell text field "To:" of window 1
			if UI element 1 exists then
				set theToRecipient to (value of UI element 1)
				if (count words of theToRecipient) is greater than 0 then return word 1 of theToRecipient
			end if
		end tell
	end tell
end tell

It doesn’t look like they have AppleScript support so you may be out of luck I’m afraid.

Thanks Rosemary. I have asked them (Zive Inc.) and they said that AS support is not currently planned, but they will consider it for the future.

1 Like

Enjoyed the email show very much. I use MailMate on macOS for my email client; one of its cool features is that it has a command-line executable, so it is script-friendly.

I use it with both Hazel (it sends an email to my wife when I download my Esso invoice) and with Keyboard Maestro. I have my own business and create invoices for my clients twice a month as PDFs. In Billings Pro, where the invoices are created, I have a custom invoice form that includes the recipient email address (in white so that it does not display on the page). I then go to the folder they’re stored in, select all and run a KM macro (which calls a Python script - with thanks to Dr Drang) via a keyboard combination - this reads the addresses, creates an email to each recipient (and adds a cc if required) and moves to the MailMate window where I can edit the message(s) if required before hitting Send. I could also automatically send them, but prefer to review first.

Thanks, David and Rose, for a very interesting new show (and for the additional accent!) - I’m finding them most illuminating.

Des

2 Likes

Hi Guys,
I was inspired by Davids simple AppleScript to start the email with the receivers first name but for the Airmail app rather than Apple Mail. What I thought was going to be simple turned out to be anything but. I can’t seem to consistently get it working for the email address in the outgoing message. Its now turning into a bit of a quest for me.

I had some success using Sender as per script below:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Airmail 3"
	set emailname to ""
	set firstname to ""
	set firstemailname to ""
	set emailname to sender of selected message
	if (count words of emailname) is greater than 0 then set firstname to word 1 of emailname
	-- returns the name prior to the @ symbol, following splits the name.surname to the name only using delimiters
	set inputStr to firstname
	set oldDelims to my text item delimiters -- save the current delimiters
	set my text item delimiters to "." -- the character to split on
	set firstemailname to first text item of inputStr -- 'text item' now refers to the string broken on the 'text item delimiter'
	set my text item delimiters to oldDelims -- just to be safe, restore the old delimiters
end tell

-- code downloaded from google to change first character of name to uppercase
property lower_alphabet : "abcdefghijklmnopqrstuvwxyz"
property upper_alphabet : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
property white_space : {space, tab, return, ASCII character 10, ASCII character 13}

set this_string to firstemailname
get change_case(this_string, "Title")

on change_case(this_text, this_case)
	set new_text to ""
	if this_case is not in {"UPPER", "lower", "Title", "Sentence"} then
		return "Error: Case must be UPPER, lower, Title or Sentence"
	end if
	if this_case is "lower" then
		set use_capital to false
	else
		set use_capital to true
	end if
	repeat with this_char in this_text
		set x to offset of this_char in lower_alphabet
		if x is not 0 then
			if use_capital then
				set new_text to new_text & character x of upper_alphabet as string
				if this_case is not "UPPER" then
					set use_capital to false
				end if
			else
				set new_text to new_text & character x of lower_alphabet as string
			end if
		else
			if this_case is "Title" and this_char is in white_space then
				set use_capital to true
			end if
			set new_text to new_text & this_char as string
		end if
	end repeat
	return new_text
end change_case

The AppleScript above only works if you are replying to the original sender of the email though. I also tried this script

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Airmail 3"
	set emailname to name of to recipient 1 of selected message
	if (count of words of emailname) is greater than 0 then return word 1 of emailname
end tell

What I would really like is if someone has found a solution to showing the current recipient of the current outgoing message as both of the above have mixed results (I think the above is for the selected message that you are replying to and not the actual reply but I might be wrong on this).

Apologies if I have posted this in the wrong place and for any lack of scripting knowledge, just trying to solve a problem :slight_smile: