2

我是脚本新手,正在尝试为邮件编写一个简单的脚本。我将在 ical 活动中使用它来发送草稿文件夹中的所有电子邮件。但是我遇到了一个错误,我不确定如何调试。这是我的脚本

tell application "Mail"
set draftMessages to every message in drafts mailbox
repeat with theMessage in draftMessages
    set theSender to (sender of theMessage)
    set theSubject to (subject of theMessage)
    set theContent to (content of theMessage)
    set theRecipients to (to recipients of theMessage)
    set theAddress to (address of theRecipients)

    set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, sender:theSender, address:theAddress, visible:true}

    end repeat
end tell

这是事件日志,其中敏感信息替换为废话。

tell application "Mail"
get every message of drafts mailbox
    --> {message id 23241 of mailbox "Drafts" of account "BLAH", message id 23236 of mailbox "Drafts" of account "BLAH"}
get sender of message id 23241 of mailbox "Drafts" of account "BLAH"
    --> "Blah Blah <blah@blah.com>"
get subject of message id 23241 of mailbox "Drafts" of account "BLAH"
    --> "test 2"
get content of message id 23241 of mailbox "Drafts" of account "BLAH"
    --> "test 2"
get every to recipient of message id 23241 of mailbox "Drafts" of account "BLAH"
    --> {to recipient 1 of message id 23241 of mailbox "Drafts" of account "BLAH"}
Result:
error "Can’t get address of {to recipient 1 of message id 23241 of mailbox \"Drafts\" of
account \"BLAH\" of application \"Mail\"}." number -1728 from «class radd» of {«class 
trcp» 1 of «class mssg» id 23241 of «class mbxp» "Drafts" of «class mact» "BLAH"}
4

2 回答 2

2

您确定要发送新消息吗?该邮件已存在于您的草稿文件夹中,没有理由创建新邮件。这应该足以做你想做的事:

tell application "Mail"
set draftMessages to every message in drafts mailbox
    repeat with theMessage in draftMessages
        send theMessage
    end repeat
end tell

如果这不是您想要的,那么您需要重写您的问题。

于 2013-06-04T11:23:04.960 回答
0

尝试将新消息移到 tell 块之外...

tell application "Mail"
    activate
    set draftMessages to every message in drafts mailbox
    repeat with theMessage in draftMessages
        tell theMessage
            set theSender to (sender of theMessage)
            set theSubject to (subject of theMessage)
            set theContent to (content of theMessage)
        end tell
        set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, sender:theSender, visible:true}
    end repeat
end tell
于 2013-06-03T18:37:53.197 回答