Mailautomization

Hello,

I’m trying to make a script which is able to send an Email with mail out of Safari to a specific recipient. I’m able to start that progress with

(email contents of document 1) open

but I’m not able to insert automatically a recipient into the “to adress” field. I tried:


tell application "Mail"
		activate
		set recipient of message 1 to "myEmailAddress"
--OR!
		tell message 1
			make new to recipient at beginning of to recipients with properties {address:addrVar, name:addrNameVar}
		end tell
	end tell

But both didn’t work. I got the message:

žMail" hat einen Fehler erhalten: recipient of message 1 kann nicht in Typ reference umgewandelt werden.
which means: Mail had received an error: recipient of message 1 cannot be changed into the reference type.

Another question: Is it possible to check if Safari is still loading to be able to wait until that is done?

Sorry if the answers for these questions are basics, but I’m just beginning to work with apple script.

Thanks!

RaGob66

This handler will send an email with an attachment. The syntax to script Mail isn’t very simple as you can see…

on send_mail_with_attachment(theSubject, theBody, theAddress, theAttachment)
	try
		tell application "Mail"
			set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return}
			tell newMessage
				set visible to false
				make new to recipient at end of to recipients with properties {address:theAddress}
				tell content
					make new attachment with properties {file name:theAttachment} at after the last paragraph
				end tell
			end tell
			send newMessage
		end tell
	on error errorMessage
		error_and_process_logging("Subroutine: send_mail_with_attachment(theSubject, theBody, theAddress, theAttachment) - " & errorMessage)
	end try
end send_mail_with_attachment

:D:D

@mattc THANK YOU FOR THE FAST REPLY! :smiley: But your script handles NEW messages in mail. And the Safari Page is only sendable as an attachment. I try to handle already opened messages in mail and I need the new Tiger possibility of


email contents of reference (e.g. document)

That command is working fine, but I hadn’t find a possibility to handle the messages in mail which are opened this way.

My (perhaps a bit stupid) complete try:


say "beginning to work"
set addrVar to "myMailAddress"
set addrNameVar to "myName"
repeat with i from 1 to 2
	tell application "Safari"
		-- make new document at end of documents
		set URL of document 1 to ("URL_Part_1" & i & "URL_Part_2")
		delay 5
		(email contents of document 1) open
		set i to i + 1
	end tell
	--tell application "Mail"
	--	activate
	--	set recipient of message 1 to "myEmailAddress"
	--	tell message 1
	--		make new to recipient at beginning of to recipients with properties {address:addrVar, name:addrNameVar}
	--	end tell
	--end tell
end repeat
say "work is done"

Thanks a lot!

ragob66

Model: iBook G4
AppleScript: 1.10
Browser: Safari
Operating System: Mac OS X (10.4)