BUG: AddRecipient broken, even with MaxProg's own example

wild_eep

New Member
The following AddRecipient line was copied & pasted directly from the document "AppleScript How-To.rtfd", but fails to produce the desired results.

Code:
tell application "MaxBulk Mailer"
	SelectList "test_list"
	AddRecipient "John Smith <[email protected]>,[email protected]"
	SaveList
end tell

Produces:


20080709-dfghm685sy3cdcrbtbfkt46e77.jpg


Notice that the first name is correctly in the 'Firstname' field (yay!), but the last name "Smith" has:

1.) also been included in the Firstname field, even though it should be in the Surname field.

2.) been truncated to "S"

3.) been concatenated with the trailing few letters from the end of the email address.
 

wild_eep

New Member
Yes, I agree that the other two examples of how to use AddRecipient work fine.

It's only the first one that fails. The problem is that when I pull information from Mail.app, it's in the form "firstname lastname <[email protected]>" (the same form that the first example uses)

Ideally I'd like for the first example to work. Alternatively, I'd like for the documentation to remove that example.
 

stanbusk

Administrator
Staff member
I will actually check the code to see why it behaves that way. First name should be 'John Smith', not 'John Sog.com'.
 

wild_eep

New Member
Hey, that's great!

Thanks for looking into it!

Here's the full code I'm using. I tested it all day yesterday.
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 theSendersName to extract name from sender of eachMessage
				set theSendersFirstName to word 1 of theSendersName
				set theSendersLastName to word 2 of theSendersName
				set theSendersAddress to extract address from sender of eachMessage
				
				-- handle the exception where someone uses their middle initial (e.g. John C Dvorak / John C. Dvorak)
				if the length of theSendersLastName is 1 or the length of theSendersLastName is 2 then
					set theSendersLastName to word 3 of theSendersName
				end if
				
				-- manipulate the text to please AddRecipient
				-- desired output is: first;last;;email-with-no-brackets
				set theRecipientText to theSendersFirstName & ";" & theSendersLastName & ";;" & theSendersAddress
				
				
				tell application "MaxBulk Mailer"
					activate
					
					-- PUT THE NAME OF THE LIST YOU CARE ABOUT 
					-- BETWEEN THE QUOTES IN THE LINE BELOW
					SelectList "first_list"
					
					
					AddRecipient theRecipientText
					SaveList
				end tell
			end tell
		end repeat
	end perform mail action with messages
end using terms from

Paste this code into Script Editor, adjust the line starting with "SelectList" to tell MBM which list to add recipients to. Save this code as a script, then in Mail.app set up a rule.

Tell the rule to select the messages you care about (doing it by subject line is easiest, especially if you slip a unique word or phrase into the subject line before it is sent to you)

Then tell the rule to apply the applescript to incoming messages.
 
Top