Sending mail to multiple recipients - weird behavior

Hello,

I’m not very skilled with Applescript, so please forgive my probably simple question.

I have a script that is supposed to send an email to multiple recipients, but is not working like it should. It looks like it worked by looking at my sent items in mail (the outgoing message is there with all of the recipients listed) however, only the first name in the list of recipients receive the mail . . . usually. Sometimes it actually works, but more times than not, only the first person in the list gets the email.

I tried to rework it so that the message is sent individually to each email address, but I couldn’t figure out how to make that work (I got an error saying the message couldn’t be opened after the 1st name on the list was sent the message)

Here is the script that I’m using


			
tell application "Mail"
				set theMessage to make new outgoing message with properties {visible:true, subject:"Online PX Today! " & weekday of (current date) & " " & month of (current date) & " " & day of (current date), content:"There is an online PX made for today. Blah blah blah. "}
				tell theMessage
					make new to recipient at end of to recipients with properties {address:"address1@mycompany.com"}
					make new to recipient at end of to recipients with properties {address:"address2@mycompany.com"}
					make new to recipient at end of to recipients with properties {address:"address3@mycompany.com"}
					make new to recipient at end of to recipients with properties {address:"address4@mycompany.com"}
					make new to recipient at end of to recipients with properties {address:"address5@mycompany.com"}
					send theMessage
				end tell
			end tell


Can anyone give me a suggestion on how to better write this script so that each person will get the email? A suggestion on how to send each person separately maybe?

Thanks

Darron

Model: MacbookPro 17 CoreDuo
Browser: Safari 528.16
Operating System: Mac OS X (10.5)

Hi,

the problem is probably, that you tell theMessage to send theMessage, which is double referenced.
For multiple recipients I recommend to use lists


set addressList to {"address1@mycompany.com", "address2@mycompany.com", "address3@mycompany.com", "address4@mycompany.com", " address5@mycompany.com", "address6@mycompany.com"}
set nameList to {"name1", "name2", "name3", "name4", " name5", "name6"}

tell (current date) to set theSubject to "Online PX Today! " & its weekday & space & its month & space & its day
tell application "Mail"
	set theMessage to make new outgoing message with properties {visible:true, subject:theSubject, content:"There is an online PX made for today. Blah blah blah. "}
	tell theMessage
		repeat with i from 1 to count nameList
			make new to recipient at end of to recipients with properties {name:item i of nameList, address:item i of addressList}
		end repeat
	end tell
	send theMessage
end tell

Thanks for the reply.

I changed it to reflect your suggestion, but the same weirdness is happening. The message appears in my sent items folder, showing all of the recipients in the to field, but the email is not arriving at the addressed inboxes.

I changed the email addresses to several different accounts that I own (gmail, hotmail, yahoo, etc) and it worked perfectly. I’m starting to think that my company may have a filter that is seeing the exact same email coming in at the exact same time from the same email address to several email addresses in the company as spam and not letting in through.

Can you give me an idea how to script a loop to send the same message to each address individually with a 5 second delay between each?

Thanks

Darron