【问题标题】:How can I perform actions on a mail created with redirect?如何对使用重定向创建的邮件执行操作?
【发布时间】:2015-12-21 04:28:02
【问题描述】:

我已经编写了 - 当然是在各种来源的帮助下 - 这个脚本批量重定向邮件:它重定向邮件应用程序中选择的所有邮件。好像没什么特别的。

tell application "Mail"
    set AppleScript's text item delimiters to ""
    set theRedirectRecipient to "redirectmail@mail.mail"
    set theRedirectSender to "Sender"
    set theMessages to the selection

    repeat with thisMessage in theMessages
        tell application "Mail"
            set theRedirectedEmail to redirect thisMessage with opening window
            tell theRedirectedEmail
                if subject of thisMessage is "" then
                    set subject of theRedirectedEmail to "Mails zonder subject"
                end if

                make new to recipient at beginning of to recipients with properties {address:theRedirectRecipient}
                #delete bcc recipients
                #delete cc recipients
            end tell
            #delay 2
            #send theRedirectedEmail
        end tell
    end repeat
end tell

如上所述,脚本运行良好:它创建重定向邮件,如果我按下发送按钮,它会像我需要的那样工作。

但是有 3 行注释掉了,不起作用。删除行和发送行。我不确定我是否关心删除的那些,但我已经将它们包括在内,以防有人能看到模式。

取消注释其中一行会给我这个错误:

error "邮件出错:无法获取外发的每个抄送收件人 消息 id 18." 来自每个 cc 传出收件人的号码 -1728 消息 ID 18

同样,这确实会创建一个消息窗口,如果手动完成,我可以成功发送。

取消注释“发送”行会引入以下错误:

error "邮件出错:传出邮件 id 19 不理解 “发送”消息。”来自传出消息 id 19 的编号 -1708

所以我得出的结论是,创建的消息不表现为消息“应该”。我已经看到 this thread 的“传出消息”似乎显示了这种行为。

这条名为theRedirectEmail 的消息是怎么回事?如何向该对象发送消息,例如 deletesend

【问题讨论】:

    标签: redirect applescript


    【解决方案1】:

    我注意到了同样的问题。这是我想出的解决方法。在某些方面,它实际上更容易:

    tell application "Mail"
        set AppleScript's text item delimiters to ""
        set theRedirectRecipient to "redirectmail@mail.mail"
        set theRedirectSender to "Sender"
        set theMessages to the selection
    
        repeat with thisMessage in theMessages
            redirect thisMessage with opening window
            tell application "System Events"
                tell application process "Mail"
                    tell window 1
    
                        --wait for mail message to appear before continuing
    
                        repeat while not (text field "To:" exists)
                        end repeat
    
                        set value of text field "To:" to theRedirectRecipient
                        set value of text field "Cc:" to ""
                        if text field "Bcc:" exists then
                            set value of text field "Bcc:" to ""
                        end if
                        if value of text field "Subject:" is equal to "" then
                            set value of text field "Subject:" to "Mails zonder subject"
                        end if
                    end tell
                    tell application "Mail" to activate
                    click menu item "Send" of menu 1 of menu bar item "Message" of menu bar 1
                end tell
            end tell
        end repeat
    end tell
    

    您必须告诉 Mail 激活,因为 Mail 不允许在后台发送电子邮件,这可能是为了防止作恶者使用 AppleScript 在您不知情的情况下在后台向您的整个联系人列表发送垃圾邮件。这也可能与邮件关于传出消息的奇怪行为有关,尽管我不能确定......

    【讨论】:

    • 好的,我想我明白了,但我不能让它与我正在使用的重复工作;您基本上使用的是两步法,有 2 个 tell 块,但是由于我处于该循环中,因此我不确定 applescript 是否知道该怎么做。关于如何将您的示例与我的代码合并的任何提示?
    • 对不起,我偷懒了。我用合并的版本更新了它。它应该可以解决问题。
    • 谢谢!正如您可能已经收集的那样,我对applescript不太了解,这真的对我有帮助:D
    • 理想情况下,我会从 tell Mail 语句中删除 Systen Events 块并将其放在自己的处理程序中。
    • @adayzdone 在这种情况下没有任何意义。如果需要,可以轻松地以这种方式重构代码,但脚本目前不需要它。始终牢记在心!
    猜你喜欢
    • 2019-11-24
    • 1970-01-01
    • 1970-01-01
    • 2014-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多