How to make Mail auto-reply to an address written in the body of incoming mail

Hi there,

trying to set up Mail to auto-reply with a simple AppleScript, but with no success.


I need to auto reply to emails with body like this:

_____

Da: stefano

Email: thisis@mailaddress.it

Telefono: 333

Arrivo: 04/03/2021

Partenza: 06/03/2021

Adulti: 2

Bambini: 0

Eta dei bambini: 

Trattamento: bb

Richieste: 

Preventivo Whatsapp: si

_____


for privacy reasons I've deleted the original field with a nonsense address, but it was an hyperlink (mailto:thisis@mailaddress.it), I think this could be important from a scripting pov.


So, on every mail from a previously specified subject and sender, I need Mail to reply with a specific text BUT to the address listed in mail's body and not to the sender.


Any help?


Thanks a lot!


Stefano


Posted on Mar 4, 2021 11:11 AM

Reply

Similar questions

2 replies

Mar 7, 2021 7:39 AM in response to StephenSword

Here is the AppleScript to extract the email address from the content of a selected message. It is not a full-blown application that then takes that email address and sends content to it. The mailto prefix is not used by Apple Mail in assigning an address to the To header field of an outgoing message.



Copy/paste the following into the Script Editor, click compile, and then with a Mail message selected, run it:


use scripting additions

tell application "Mail"
	if not it is running then activate
	
	if not (get selection) is {} then
		set theMsg to item 1 of (get selection)
	else
		return
	end if
	
	tell theMsg
		set theContent to its content
	end tell
end tell
set email_addr to my extract_email(theContent) as text
if email_addr contains "@" then
	display dialog email_addr with title "Captured E-mail address"
else
	display alert "Email address not found."
end if
return

on extract_email(astr)
	# a space, a non-breaking space, and a colon
	set DELIM to {space, " ", ":"}
	set EMAIL_PREFIX to {"Email", "mailto"}
	set found to "None"
	
	repeat with aline in paragraphs of astr
		set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, DELIM}
		set tmp to text items of (aline as text)
		set AppleScript's text item delimiters to TID
		if not (tmp = {}) and (EMAIL_PREFIX contains (first item of tmp)) then
			set found to (last item of tmp) as text
		end if
	end repeat
	
	return found
end extract_email


Mar 7, 2021 6:09 AM in response to StephenSword

Greetings, Stefano!


Thanks for reaching out to the Apple Support Communities! If we understand correctly, you're looking for help with creating auto-reply rules for your Mac Mail app. We can understand wanting to get this set up. We'll do all we can to help get you pointed in the right direction.


To verify, do you want to create this rule/auto-reply for a Mac/iCloud email account? If not, who is the email provider for this? If this is an iCloud account, you can set up automatic replies to all emails by following these steps: Set up an automatic reply in Mail on iCloud.com.


If it is not an account through Apple, you can create rules within the Mail app. Here's a guide with information on how to Use rules to manage emails you receive in Mail on Mac. Additionally (if needed), you can Use scripts as rule actions in Mail on Mac. If the issue remains, you may want to contact your email provider to see if they have an option to create rules for auto-replying directly from your mail server.


Take care!

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.

How to make Mail auto-reply to an address written in the body of incoming mail

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