如何对使用重定向创建的邮件执行操作?

How can I perform actions on a mail created with redirect?

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

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 "Mail got an error: Can’t get every cc recipient of outgoing message id 18." number -1728 from every cc recipient of outgoing message id 18

同样,这确实创建了一条消息 -window 如果手动完成,我可以成功发送。

取消注释 'send' 行会引入以下错误:

error "Mail got an error: outgoing message id 19 doesn’t understand the “send” message." number -1708 from outgoing message id 19

所以我得出的结论是,创建的消息不作为消息 'should'。我已经看到 this thread 一个 'outgoing message' 似乎表现出这种行为。

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

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

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。这也可能与邮件关于外发邮件的奇怪行为有关,虽然我不能确定...