| Author |
Message |
wild_eep
Joined: 02 Jul 2008 Posts: 9 Location: Rochester, NY
|
Posted: Wed Jul 02, 2008 2:36 am Post subject: Applescript Mail.app incoming messages to MBM recipient list |
|
|
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;<john@maxprog.com>"
SaveList
end tell
|
|
|
| Back to top |
|
 |
stanbusk Site Admin
Joined: 28 Dec 2005 Posts: 2189
|
Posted: Wed Jul 02, 2008 8:26 am Post subject: |
|
|
| I guess you have problems gettings the data from the mail application right? |
|
| Back to top |
|
 |
wild_eep
Joined: 02 Jul 2008 Posts: 9 Location: Rochester, NY
|
Posted: Wed Jul 02, 2008 4:14 pm Post subject: |
|
|
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 <jdoe@example.com>"
Can anyone point me to a credible, easy-to-follow reference for pulling information reliably from Leopard's Mail.app? |
|
| Back to top |
|
 |
stanbusk Site Admin
Joined: 28 Dec 2005 Posts: 2189
|
Posted: Wed Jul 02, 2008 6:21 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
wild_eep
Joined: 02 Jul 2008 Posts: 9 Location: Rochester, NY
|
Posted: Thu Jul 03, 2008 2:54 pm Post subject: |
|
|
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: | Quote: | Adding recipients: AddRecipient
Add recipients to the list (Optional)
Following forms are allowed:
AddRecipient "John Smith <john@maxprog.com>,cherryl@maxprog.com"
AddRecipient john@maxprog.com,cherryl@maxprog.com
AddRecipient "Richard;Wagner;MaxProg;richard@maxprog.com" |
So perhaps I only need to pass 'theSender' to the AddRecipient method. |
|
| Back to top |
|
 |
wild_eep
Joined: 02 Jul 2008 Posts: 9 Location: Rochester, NY
|
Posted: Thu Jul 03, 2008 3:11 pm Post subject: |
|
|
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?
 |
|
| Back to top |
|
 |
|