Setting reply to address when composing new mail

Hi all

How do you set the “reply to” address through Applescript when composing a new mail? I’m running this script:

tell application “Mail”
set newMessage to make new outgoing message with properties {subject:“Subject”, content:“Message body” & return & return}
tell newMessage
set sender to “Sender sender@sender.co.uk
make new to recipient at end of to recipients with properties {name:“”, address:"recipient@recipient.co.uk"}
end tell
send newMessage
end tell


I’ve tried this which doesn’t work:

tell application “Mail”
set newMessage to make new outgoing message with properties {subject:“Subject”, reply to: “Reply to replyto@replyto.com”, content:“message body” & return & return}
tell newMessage
set sender to “Sender sender@sender.co.uk
make new to recipient at end of to recipients with properties {name:“”, address:"recipient@recipient.co.uk"}
end tell
send newMessage
end tell


and I’ve tried this which generates an error:

tell application “Mail”
set newMessage to make new outgoing message with properties {subject:“Subject”, content:“message body” & return & return}
tell newMessage
set sender to “Sender sender@sender.co.uk
set reply to to “Reply to replyto@replyto.com
make new to recipient at end of to recipients with properties {name:“”, address:"recipient@recipient.co.uk"}
end tell
send newMessage
end tell


The error I get is “Mail got an error: Can’t make reply to of outgoing message ID 100699664 into type reference”

Help!

Wanderer:

This is an interesting problem you have hit upon. The [reply to] property is only available in the class [message], not the class [outgoing message]. (See the dictionary.) It appears on the surface that one can only utilize the [reply to] property in a message that has been recieved already (see scriplet below).

tell application "Mail"
	set a to first message in mailbox "PUT A NAME OF A MAILBOX HERE"
	reply to of a
end tell

Unfortunately, when trying to access that property of an [outgoing message], one gets the nasty error. I have not got much time to play with it right now, but I would like to try building a message, use that parameter, and then make it an outgoing message and see if it works.

The only other fix I can see is to use the address you want replies sent to as the [sender] property, but that may also induce problems.

Good luck; I will re-post here in a few days if I can come up with any more information.

Wanderer:

It appears that the [reply to] property is read-only, even though the Mail dictionary does not identify it as such. I tried taking a message from one of my inboxes and changing the [reply to] to a different address so that I could simply forward the message, hoping this could be a work around for your situation. Unfortunately, that is not going to happen.

It looks like the only way you can control that property is by using the [sender] property, which automatically makes the [reply to] property correct.

Hope this helps.