iCloud email rule: move to folder and notify me?

Hi,

Wondering if anyone could help with the following? I volunteer for an organisation and would like to setup an automated workflow which:

  • moves any emails from the organisation into an iCloud mail folder
  • alerts me in some way that I have an email from them (preferably not a device notification - would rather receive an email or some other asynchronous approach)

I use Omnifocus, so if forwarding on via my unique Omni email address is a good way, then that would be good.

My primary reason for wanting to do this is so that I only see volunteering information and requests when in “doing mode”. Don’t want to open my personal email and see that kind of thing. I could just setup another email address, but at this point would like to see if I can solve it without asking the volunteer organisation to change anything at their end.

Thanks in advance for your help :smile:

I have a number of server side rules (set via iCloud.com) that presorts my mail on the server so it’s done regardless of which device I use to read it. As example all the emails from various tech publications go into a mailbox named “Computer Mags”. The new message count shows me I have messages there but I don’t open that mailbox unless I want to read them. Could a process like that work for you?

Hi,

This is quick and dirty but should be what you are after.

Make the necessary changes to the Configurations settings and save the script to /Users/(Your userName)/Library/Application Scripts/com.apple.mail.

Create a mail rule to run the Applescript against every message or be specific to the Organsition’s email address, subject etc.

There will be a Hyperlink to the Organisations email in the alert email to make processing the items easier.

Hope it helps

Iain

#############################################
# Title: Organisation eMail Alert
############################################

# Iain Dunn
# Logic2Design
# www.logic2design.com
# logic2design@icloud.com

# Last update: 9 February 2022
# Version: 1

# Contributors and sources
# 

##############################################
# Configuration
##############################################

set theSender to "@" -- the Organisation email address
set theFrom to "@" -- Your email
set theForward to "@" -- the email address you want to send the alert to
set theSubject to "Alert - you have received an email from the Organisation" --eMail Subject
set theArchive to "Test" --name of iCloud Mail folder where to save the Organisation's email

##############################################
# Code
##############################################

tell application "Mail"
	
	--Get the messages in the Inbox
	set messageList to every message in inbox whose sender contains (theSender as list)
	
	repeat with theMessage in messageList
		
		# Get the message URL
		set theOrigMessageId to theMessage's message id
		set theUrl to {"message://%3C" & my replaceText("%", "%25", theOrigMessageId) & "%3E"}
		
		--Send alert
		tell application "Mail"
			set theNewMessage to make new outgoing message with properties {sender:theFrom, subject:theSubject, content:"Organisation eMail - " & theUrl, visible:false}
			tell theNewMessage
				make new recipient at end of to recipients with properties {address:theForward}
			end tell
			send theNewMessage
		end tell
		
		# Archive the Organisation's Message
		tell application "Mail"
			set mailbox of theMessage to mailbox theArchive of account "iCloud"
		end tell
		
	end repeat
end tell

##############################################
# Functions
##############################################

on replaceText(find, replace, textString)
	set prevTIDs to AppleScript's text item delimiters
	set AppleScript's text item delimiters to find
	set textString to text items of textString
	set AppleScript's text item delimiters to replace
	set textString to "" & textString
	set AppleScript's text item delimiters to prevTIDs
	return textString
end replaceText
1 Like