(**
  *	filename: MailNotification.applescript
 *	created : Tue Feb 11 14:24:40 2003
 *	LastEditDate Was "Mon Jun 30 11:25:23 2003"
 *
 *)

(* recipientAddress is a list of Addresses to send to
 * messageSubject is the subject of the spam message
 * messageBody is the body of the spam message
 *)
on sendemail(emailer, vcardPath, recipientAddress, messageSubject, messageBody)

	(* Part that does all of the work, this works for Mail *)
	if (emailer is equal to "com.apple.mail") then
		tell application "Mail"
			-- Properties can be specified in a record when creating the message or
			-- afterwards by setting individual property values.
			set newMessage to make new outgoing message with properties {subject:messageSubject, content:messageBody}
			tell newMessage
				-- Default is false. Determines whether the compose window will
				-- show on the screen or whether it will happen in the background.
				set visible to false

				repeat with emailAddress in recipientAddress
					make new bcc recipient at end of bcc recipients with properties {address:emailAddress}
				end repeat
				tell content
					-- Position must be specified for attachments
					make new attachment with properties {file name:vcardPath} at after the last paragraph
				end tell
			end tell
			-- send the message
			send newMessage
		end tell
	else
		if (emailer is equal to "com.microsoft.entourage") then
			(* lots of stuff for entourage here *)
		end if
	end if
end sendemail

-- sendemail("com.apple.mail", "/tmp/foo.vcf", "dude@apple.com", "messageSubject", "messageBody")
