Mail.app auto reply script - help needed

Hi guys,

I’m trying to set up a script that would be called by a rule in Mail.app, which would send an automated reply message to certain senders.

The details:
¢ changed e-mail address
¢ old address (Mail.com / AOL) configured to forward everything to my new address (Google Apps)
¢ want the sender of every one of these forwarded messages to automatically receive a message about my new address

I surfed around and cribbed a script from another forum (built for a slightly different purpose from mine) and tried to adapt it. But it doesn’t seem to work. Fixing it is well beyond my geekery.

Here’s the script as I currently have it:

using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		tell application "Mail"
			repeat with thisMessage in theMessages
				set AppleScript's text item delimiters to {""}
				set thisSender to sender of theMessages
				
				set theNewMessage to reply thisMessage with opening window
				tell theNewMessage
					set fromAccount to account "mynewaccount"
					set content to "This is an automated reply. Your message has been forwarded to my new e-mail address. For future reference, please update your records by replacing my former address oldusername@olddomain.com with my new address newusername@newdomain.com .

Thankyou,
Lance"
				end tell
				
				send theNewMessage
				
			end repeat
		end tell
	end perform mail action with messages
end using terms from

Can someone help me, please. Thanks.

Model: macbook 2.16G (mid-2007)
AppleScript: 2.1.2
Browser: Safari 533.17.8
Operating System: Mac OS X (10.6)

Well if you’ve forwarded the message, i would expect it to never appear in that account. i would update the script to use the TO: address field to send the auto reply.

Model: MacBook Pro 13"
Browser: Safari 533.17.8
Operating System: Mac OS X (10.6)

Thanks, Kim. (Another Aussie too, I see … :slight_smile:

I clearly need to explain my setup better …

The forwarding is setup on the server in the old account (I did that in the account settings through the web interface).

I’ve disabled the old account in Mail.app

I access the new account exclusively in Mail.app by IMAP.

The condition for the rule that calls the script is the presence of a header created by the AOL server in the forwarding process.

Thus - hopefully! - the script is acting on all incoming messages forwarded from the old account to the new one (and no others).

I have since picked up a reference in another forum to the need for a delay before sending, specific to 10.6 . So I’ve now added “delay 5” immediately above the send. Haven’t had a forwarded message since doing that. Guess we’ll see …

Any other wisdom?

You could have a script grab content from Mail, then send replies via command line back to them in the same email address.

Just to report back for info … I searched around some more and cribbed another script that takes a different approach. I blended elements of that script with the earlier one, and included the pre-send delay.

It’s probably pure luck, given my general noob-ness - but it actually works :smiley: Since I pinched it from the work of two others, I hardly care whether anyone acknowledges my part in putting it together.

My two sources are here and here.

And this is the cobbled script that miraculously works. Maybe it will help some other noob one day …

using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		tell application "Mail"
			repeat with thisMessage in theMessages
				set theName to extract name from sender of thisMessage
				if exists reply to of thisMessage then
					set theAddress to reply to of thisMessage
				else
					set theAddress to extract address from sender of thisMessage
				end if
				set theNewMessage to make new outgoing message
				tell theNewMessage
					make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
					set visible to false
					set subject to "Re: " & subject of thisMessage & "- Change of address"
					set sender to "My Name <myusername@mydomain.com>"
					set content to "Dear " & theName & ",

This is an automated reply. Your message has been forwarded to my new e-mail address. For future reference, please update your records by replacing my former address myoldusername@myolddomain.com with my new address mynewusername@mynewdomain.com .

Thankyou,
Me"
				end tell
				delay 5
				send theNewMessage
				tell thisMessage
					set was replied to to true
				end tell
				
				
			end repeat
		end tell
	end perform mail action with messages
end using terms from