views:

67

answers:

1

I'm trying to reply to a mail in Mail.app with py-appscript.

I tried the code below,

from appscript import *

mailapp = app('Mail')

# get mail to be replied
msg = mailapp.accounts.first.mailboxes.first.messages.first

# create reply mail
reply_msg = mailapp.reply(msg)

# set mail (got error)
reply_msg.visible.set(True)
reply_msg.subject.set('replied message')
reply_msg.content.set('some content')

but got following error, it failed to set subject. (setting visible property is succeeded)

CommandError: Command failed:
        OSERROR: -10000
        MESSAGE: Apple event handler failed.
        COMMAND: app(u'/Applications/Mail.app').outgoing_messages.ID(465702416).subject.set('replied message')

It works when I use "make" instead of "reply" to create new message.

# create new mail
msg = mailapp.make(new=k.outgoing_message)

# set mail (works fine)
msg.visible.set(True)
msg.subject.set('new mail')
msg.content.set('some content')

Can you please tell me what this error is and how to fix it?

A: 

Works fine on 10.6 but there's a bug in Mail on 10.5 (and probably earlier) that causes outgoing messages created by the reply command not to work correctly.

If you have to support 10.5, I think your only option is to build a new outgoing message from scratch, copying the relevant information from the message you're replying to yourself.

has
Thank you very much! It's a big help.Now, I have no snow leopard environment in my home, so I'll check it at office tomorrow!
taichino
Hi, I checked on snow leopard, and another problem is occuring.This time, I can set "subject" property, but I failed to set "content" property. I'm using OSX 10.6.4 and Mail.app 4.3, can you please tell me how can I fix it?
taichino
Looks like Mail's `reply` command is still glitchy. I tried replying to one mail and it worked fine, inserting both quoted text from the original message and the new content text. Replying to another mail though, the content area was left completely blank. No idea why - I'm not a Mail guru. I can only suggest filing a Radar bug and asking on the applescript-users mailing list - perhaps someone there can say more about the vagaries of Mail scripting.
has
Umm... I have same situation.Okay, I'll ask the mailing list for help and report results.Thank you very much for your advice!
taichino
Hi, I asked applescript-users and they taught me some useful advice!As the result, before call reply method, Mail.app need to be activated. It is also efficient as using py-appscript!
taichino