Applescript Mail.app incoming messages to MBM recipient list

wild_eep

New Member
Hello,

I have a web form on a website that emails me when people express interest in joining my mailing list.

My email client is Leopard's Mail.app

One of the actions it can perform on incoming messages is to run an AppleScript

I want to write an AppleScript that takes a given message, pulls the 'from' name and email address, and adds it to a particular recipient list in MBM.

So far, I *have* been able to add arbitrary names and addresses to MBM recipient lists using AppleScript.

The trouble is when I try to get the names and addresses from the incoming email. Either the scripts aren't firing, or AppleScript can't get the name/address that I want. I can't tell what's going on.

Has anyone tried this before? Do you have some sample code you'd be willing to share?

Here's what I used as a 'proof-of-concept'

Code:
			tell application "MaxBulk Mailer"
				activate
				SelectList "first_list"
				AddRecipient "John;Smith;<[email protected]>"
				SaveList
			end tell
 

wild_eep

New Member
Yes, that's right.

I've even tried something simple:
Code:
tell application "Mail"
	set foo to extract name from sender of message 270456 of mailbox "INBOX" of account "dwurster - gmail"
	display dialog foo
end tell

Which produces the error: "Mail got an error: Unrecognized direct parameter type, please specify a string like "John Doe <[email protected]>"

Can anyone point me to a credible, easy-to-follow reference for pulling information reliably from Leopard's Mail.app?
 

stanbusk

Administrator
Staff member
Try:
Code:
tell application "Mail" 
 set mymailbox to mailbox "MAILBOX_NAME_HERE"
 set msgs to every message in mymailbox
 repeat with mymessage in msgs
  set mySender to sender of mymessage as text
  tell application "MaxBulk Mailer"
    AddRecipient mySender
  end tell				
 end repeat
end tell
I am not sure how to add the data of a single message though.
 

wild_eep

New Member
I've put together some code, and I think I'm getting pretty close.

Code:
using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		repeat with eachMessage in theMessages
			tell application "Mail"
				set theSender to extract name from sender of eachMessage
				set theAddress to extract address from sender of eachMessage
				set FirstName to word 1 of theSender
				set LastName to word 2 of theSender
				tell application "MaxBulk Mailer"
					activate
					SelectList "first_list"
					AddRecipient FirstName & ";" & LastName & ";" & theAddress
					SaveList
				end tell
			end tell
		end repeat
	end perform mail action with messages
end using terms from

The email address shows up fine in the recipient list of MBM, but the first and last names get somewhat clobbered.

The documentation states:
Adding recipients: AddRecipient
Add recipients to the list (Optional)
Following forms are allowed:

AddRecipient "John Smith <[email protected]>,[email protected]"
AddRecipient [email protected],[email protected]
AddRecipient "Richard;Wagner;MaxProg;[email protected]"

So perhaps I only need to pass 'theSender' to the AddRecipient method.
 

wild_eep

New Member
I just got an email from "Jeff Agnello", but the firstname passed to MBM was "Jeff Agcom.com", and no Surname was passed.

Looks like the last 7 characters of the email address were somehow imposed on the tail end of the name.


Seems like I'm *so* close on this script... Anyone have any ideas about what to try next?

MBM_script_results.gif
 
Top