Py-appscript:如何使用Mail.app发送消息?

0 投票
1 回答
560 浏览
提问于 2025-04-16 00:44

我正在尝试用py-appscript(一个让Python可以使用AppleScript的工具)来创建邮件。

from appscript import *

mail = app('Mail')
msg = mail.make(new=k.outgoing_message,
                with_properties={'visible':True,
                                 'content':"hello",
                                 'subject':"appscript",
                                 'sender':'taichino@gmail.com'
                                 })

但是我遇到了以下错误信息,我找不到任何相关的信息来解决这个问题...

CommandError: Command failed:
  OSERROR: -1701
  MESSAGE: Some parameter is missing for command.
  COMMAND: app(u'/Applications/Mail.app').make('outgoing_message', with_properties={'content': 'hello', 'visible': True, 'sender': 'taichino@gmail.com', 'subject': 'appscript'})

有没有什么建议呢?

1 个回答

0

我自己解决了这个问题,下面的代码运行得很好。

from appscript import *

mail = app('Mail')
msg = mail.make(new=k.outgoing_message)
msg.subject.set("hello"),
msg.content.set("appscript")
msg.to_recipients.end.make(
    new=k.to_recipient,
    with_properties={k.address: 'taichino@gmail.com'}
)
msg.send()

与其在构造函数里一次性设置所有属性,不如一个一个地单独设置每个属性。

撰写回答