Using Mail

Hi,

I am currently trying to automate a system where as soon as my customers send me money via paypal, Mail searches my mailbox for emails with “Instant Payment” in their subject.

I then want applescript to extract the email address of my customer and send a message to them, inside the message, there will be an attachment of a photo of a code.

The customers are paying for a code, and each code is different.

I will have quite alot of customers in a short amount of time, hence why I am trying to automate the system.

I will number the images from 1 to 100 so applescript can send a different image each time.

I have managed to put together a script which looks at my desktop and takes those images and can send each to my customer.

I also made a script which can extract the email addresses of the customers in my inbox who have paid me(I do this by using "every message of inbox whose subject contains “Instant”) , however I need to implement it with the other script.

These are my scripts.

set bnum to 1

repeat
	tell application "Mail"
		set rnumber to bnum
		set theAttachments to {"Users/kadvani/Desktop/" & rnumber & ".jpg"}
		set emailadd to display dialog "Enter Customer's Email Address" default answer ""
		set addr to text returned of emailadd
		set subj to "code"
		set body to "Thank you for your purchase, here is your code"
		set msg to make new outgoing message with properties {subject:subj, content:body}
		tell msg
			make new to recipient at end of to recipients with properties {address:addr}
		end tell
		tell content of msg
			repeat with theAttachment in theAttachments
				make new attachment with properties {file name:theAttachment} at after last paragraph
				
				
			end repeat
			display dialog "Would you like Code " & bnum & " to be sent?" buttons {"Send", "Cancel"}
			if button returned of result is "OK" then
				send msg
			end if
			send msg
			set bnum to bnum + 1
			
			
			
		end tell
	end tell
end repeat
tell application "Mail"
	set newMessages to (every message of inbox whose subject contains "Instant")
	
	repeat with eachMessage in newMessages
		set theSendersAddress to extract address from sender of eachMessage
		
		
		
		
	end repeat
	
end tell

If you could tell me how to implement the 2, it would be much appreciated.

Thanks.

Hi,

you need a rule with the condition subject contains “Instant” and this script.
The only point, I’m concerned about, is whether the property value survives the next call of the script.
If not, you need a script object as a preference file, which keeps the value on disk

property bnum : 1

using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		repeat with eachMessage in theMessages
			tell application "Mail"
				set theSendersAddress to extract address from sender of eachMessage
				set theAttachment to POSIX path of (path to desktop) & bnum & ".jpg"
				set subj to "code"
				set body to "Thank you for your purchase, here is your code"
				set msg to make new outgoing message with properties {subject:subj, content:body}
				tell msg
					make new to recipient at end of to recipients with properties {address:theSendersAddress}
					tell content to make new attachment with properties {file name:theAttachment} at after last paragraph
					send
				end tell
				set bnum to bnum + 1
			end tell
		end repeat
	end perform mail action with messages
end using terms from